Qml StateELement中的Scale元素
我可以在下面写几行,让它工作起来:Qml StateELement中的Scale元素,qml,Qml,我可以在下面写几行,让它工作起来: states: State { name: "active"; when:myitem.activeFocus; PropertyChanges { target: myitem; z:1000; scale: 1.2 } }
states: State {
name: "active"; when:myitem.activeFocus;
PropertyChanges { target: myitem; z:1000; scale: 1.2 }
}
transitions: Transition {
NumberAnimation { properties: scale; duration: 1000 }
}
但在这些行中,我无法给出缩放属性的具体原点
我找到了比例元素
transform: Scale { origin.x: 25; origin.y: 25; xScale: 3}
我如何将其注入到上面的state属性中,因为我想使用state的“when”属性
我希望缩放在“何时”条件下运行
或者有没有其他方法可以在指定原点的条件下进行缩放
谢谢你的建议。你应该为
比例
元素设置一个id
。然后可以在“活动”状态下更改其属性
下面是一个简单的工作示例:
import QtQuick 1.0
Item {
height: 200; width: 500
Rectangle {
id: myitem
height: 10; width: 100
anchors.centerIn: parent
color: "blue"
transform: Scale { id: scaleTransform; origin.x: 25; origin.y: 25 }
states: State {
name: "active"; when: mouseArea.pressed
PropertyChanges { target: scaleTransform; xScale: 3 }
}
transitions: Transition {
NumberAnimation { property: "xScale"; duration: 1000 }
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
}
}
没有国家的另一种可能性是:
import QtQuick 1.0
Item {
height: 200; width: 500
Rectangle {
id: myitem
height: 10; width: 100
anchors.centerIn: parent
color: "blue"
transform: Scale {
id: scaleTransform
origin.x: 25; origin.y: 25
xScale: mouseArea.pressed ? 3 : 1 // <-
Behavior on xScale { // for animation
NumberAnimation { duration: 1000 }
}
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
}
}
导入QtQuick 1.0
项目{
高度:200;宽度:500
长方形{
id:myitem
高度:10;宽度:100
anchors.centerIn:父对象
颜色:“蓝色”
变换:缩放{
id:scaleTransform
原点x:25;原点y:25
xScale:mouseArea.pressed?3:1//谢谢,我找到了解决方案,但我不知道如何对其进行编号和动画制作。有用的帖子