Rectangle {
id: rect3
width: 50
height: 50
x: 75
y: 330
color: "#FF4C3B"
Text {
id: text3
x: 8
y: 0
width: 50
height: 50
color: "#FFFFFF"
font.family: "Ubuntu"
text: "►"
font.pixelSize: 40
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
animation5.start()
text3.text= "abcdefghijklmno"
text3.width=animation5.width
}
onExited: {
animation6.start()
text3.text="►"
text3.width=animation6.width
}
NumberAnimation {
id: animation5
target: rect3
property: "width"
to: 350;
duration: 1000
}
NumberAnimation {
id: animation6
target: rect3
property: "width"
to: 50;
duration: 1000
}
}
}
}
我可以将文本的宽度设置为NumberAnimations中增加/减少的宽度吗?我希望文本使用矩形一次缩放大小。我认为text3.width=animation5.width
函数中的onEntered
和text3.width=animation6.width
函数中的onExited
会这样做,但它看起来并不像?有什么想法吗?
答案 0 :(得分:0)
如果动画的目标是矩形:
Rectangle {
...
Text {
...
width: parent.width
}
答案 1 :(得分:0)
Rectangle {
id: rect3
width: 50
height: 50
x: 75
y: 330
color: "#FF4C3B"
Text {
id: text3
x: 8
y: 0
width: 50
height: 50
color: "#FFFFFF"
font.family: "Ubuntu"
text: "►"
font.pixelSize: 40
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
animation5.start()
text3.text= "abcdefghijklmno"
textanim5.start()
}
onExited: {
animation6.start()
text3.text="►"
textanim6.start()
}
NumberAnimation {
id: animation5
target: rect3
property: "width"
to: root.width-150;
duration: (10*(root.width-150))/3.5
}
NumberAnimation {
id: animation6
target: rect3
property: "width"
to: 50;
duration: (10*(root.width-150))/3.5
}
NumberAnimation {
id: textanim5
target: text3
property: "x"
to: root.width-200
duration: (10*(root.width-150))/3.5
}
NumberAnimation {
id: textanim6
target: text3
property: "x"
to: 8
duration: (10*(root.width-150))/3.5
}
}
}
}