【发布时间】:2015-09-11 04:45:16
【问题描述】:
我想通过修改 height 来显示/隐藏一个元素。这是显示我的问题的示例代码:
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.4
Window {
id: win
width: 300
height: 300
visible: true
ColumnLayout {
width: parent ? parent.width : 200
Switch {
id: someswitch
Layout.alignment: Qt.AlignCenter
}
Label {
id: myText
text: "dummy"
height: 0
wrapMode: Text.WordWrap
clip: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
states: State {
name: "visible"
when: someswitch.checked
PropertyChanges { target: myText; height: implicitHeight }
}
Behavior on height {
NumberAnimation { duration: 100 }
}
}
}
}
我还没有添加Transition/Animation,但是这个阶段的行为已经是错误的。 someswitch 默认未选中,但会显示文本。另一方面,在检查开关后,文本隐藏并且不再出现。
我应该如何处理?我希望文本“滑出”。我不想更改它的opacity。
【问题讨论】: