2017-06-06 99 views
1

我已經制作了其代表是RowLayout的列表,其中包含按鈕。該列表從cpp獲取數據。Qml按鈕修復大小

我的問題是按鈕變量寬度。按鈕側根據數據而改變。我想保持固定按鈕側和文本換行

回答

1

爲了讓你的Button固定寬度,只需用相同名稱的屬性設置爲一個固定值。

Button有一個contentItem這是一個Text。您可以在那裏更改wrapModeText.WordWrap

由於contentItem的類型是Item你不能設置wrapMode這樣的:

Button { 
    width: 100 
    text: 'Very very long button description.' 
    contentItem.wrapMode: Text.WordWrap // Won't work 
} 

相反,你可以使用Component.onCompleted這樣的:

Button { 
    width: 100 
    text: 'Very very long button description.' 
    Component.onCompleted: contentItem.wrapMode = Text.WordWrap 
}