答案 0 :(得分:1)
Text
项给您WrapMode
。请参阅here
您可以以此为例: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"}