qt - 如何管理 QPushButton 文本中的长字符串?
解决方案
Text
项目给你WrapMode
。参考这里
你可以以此为例:MyButton.qml
import QtQuick 2.0
Rectangle {
id: buttonRect
height: 40
width: 200
color: "#404040"
radius: 5
property alias buttonText: text
signal clicked()
Rectangle {
id: maskRect
anchors.fill: parent
color: "#575757"
radius: buttonRect.radius
visible: buttonMousearea.pressed
}
Text {
id: text
text: qsTr("Button")
color: "white"
width: parent.width
anchors.centerIn: parent
wrapMode: Text.Wrap
}
MouseArea {
id: buttonMousearea
anchors.fill: buttonRect
hoverEnabled: true
acceptedButtons: Qt.LeftButton
onClicked: buttonRect.clicked()
}
states: [
State {
name: "hasMouse"
when: buttonMousearea.containsMouse
PropertyChanges {
target: buttonRect
color: "#6e6e6e"
}
PropertyChanges {
target: buttonMousearea
cursorShape: Qt.PointingHandCursor
}
}
]
}
然后像下面这样使用它
MyButton {buttonText.text: "something which is really longer than the button"}
推荐阅读
- vim - Vim: 禁用 autocmd BufRead (modeline)
- java - 电报机器人仅用于发送消息
- android - 应用更新时 WorkManager 的队列会被清空吗?
- firebase - Pkg:从文件中读取错误。尝试在控制台中检查 firebase CLI 版本时(firebase -V)
- c++ - 请帮我澄清 C++ 按值传递?
- kubernetes - 问题设置应用程序网关入口控制器(agic)azure kubernetes 服务(aks)
- flutter - 波纹效果确实适用于列表图块中的长按
- java - 如何根据存储的双倍分数对字符串列表进行排序?
- terraform - Terraform:有条件的 AWS EMR 步骤
- python - Python:在一个不返回任何东西的函数上