Qt 高度动画不起作用
我正在尝试创建Qt 高度动画不起作用,qt,qml,tableview,qt5,Qt,Qml,Tableview,Qt5,我正在尝试创建TableView,其中的行可以在单击时展开并显示一些内容。它可以工作,但不显示高度特性动画。我尝试添加ColorAnimation并将扩展行颜色更改为黑色,效果很好,但由于某些原因,它对高度不起作用。 以下是我的表视图的代码: TableView { id: myTableView anchors.right: parent.right anchors.left: parent.left anchors.bottom
TableView
,其中的行可以在单击时展开并显示一些内容。它可以工作,但不显示高度特性动画。我尝试添加ColorAnimation
并将扩展行颜色更改为黑色,效果很好,但由于某些原因,它对高度不起作用。
以下是我的表视图的代码:
TableView {
id: myTableView
anchors.right: parent.right
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.bottomMargin: 12
anchors.leftMargin: 10
anchors.top: parent.top
anchors.topMargin: 12
anchors.rightMargin: 10
model: myModel
ListModel {
//...
}
rowDelegate: Item {
id: myRowDelegate
Rectangle {
id: rect
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
color: styleData.alternate ? "#d9e5ea" : "white"
MouseArea {
anchors.fill: parent
onClicked: {
myRowDelegate.state = (myRowDelegate.state == "COLLAPSED") ? "EXPANDED" : "COLLAPSED";
console.log("click");
}
}
}
state: "COLLAPSED"
states: [
State {
name: "COLLAPSED"
PropertyChanges { target: myRowDelegate; height: 22; }
},
State {
name: "EXPANDED"
PropertyChanges { target: myRowDelegate; height: 400; }
// PropertyChanges { target: rect; color: "black"; }
}
]
transitions: [
Transition {
from: "EXPANDED"
to: "COLLAPSED"
PropertyAnimation { property: height; duration: 400; }
// ColorAnimation { duration: 400; }
},
Transition {
from: "COLLAPSED"
to: "EXPANDED"
PropertyAnimation { property: height; duration: 400; }
//ColorAnimation { duration: 400; }
}
]
}
}
}
必须将属性名称用作字符串才能使其正常工作:
PropertyAnimation{property:
“高度”;持续时间:400;}
您还可以通过行为(删除该行为的转换)实现这一点:
非常感谢你!我添加了“height”
,现在它可以正常工作了。你为我节省了很多时间,谢谢。@d'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''?
Behavior on height {
NumberAnimation { duration: 400 }
}