文本更改上的动画按钮宽度
我有一个按钮,该按钮会更改文本,其文本更改时,其宽度也会改变。当我更改文本时,我想对宽度进行动画变化。我该怎么做?
我尝试关注但不起作用
import QtQuick.Window 2.15
import QtQuick 2.15
import QtQuick.Controls 2.15
Window {
width: 500
height: 600
visible: true
Button {
property bool t: false
text : t ? "very more text hahaha haha hehe" : "less text"
onClicked: t = !t
Behavior on width {
NumberAnimation {
duration: 1000
}
}
}
}
I have a Button which text changes and when its text changes, its width also changes. I want to animate this change in width when I change the text. How can I do that ?
I tried following but its not working
import QtQuick.Window 2.15
import QtQuick 2.15
import QtQuick.Controls 2.15
Window {
width: 500
height: 600
visible: true
Button {
property bool t: false
text : t ? "very more text hahaha haha hehe" : "less text"
onClicked: t = !t
Behavior on width {
NumberAnimation {
duration: 1000
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按钮宽度的更改是其隐式宽度在这里更改的副产品。
通过将行为更改为触发
indimitwidth
而不是width
,您将具有预期的行为。The change of the Button width is a byproduct of its implicitWidth being changed here.
By changing the Behavior to trigger on
implicitWidth
instead ofwidth
you will have your expected behavior.