![](/img/trans.png)
[英]How to auto change QPushButton width and QMenuBar corner widget width when change text of button?
[英]Animate Button width on text change
我有一个按钮,它的文本会发生变化,当它的文本发生变化时,它的宽度也会发生变化。 我想在更改文本时为宽度变化设置动画。 我怎样才能做到这一点 ?
我尝试关注但它不起作用
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
}
}
}
}
Button 宽度的变化是其implicitWidth 在此处更改的副产品。
通过将行为更改为在implicitWidth
宽度而不是width
上触发,您将获得预期的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.