[英]QT Text.WordWrap not working inside ColumnLayout
我正在使用QT QML開發應用程序。 我正面臨着QML的一個奇怪問題。 我想使用QML划分和顯示長文本。 我正在使用QT Text元素來執行此任務。 我想將此Text放在QT Columnlayout中,並與其他UI元素一起使用。 我無法將長文本顯示為多行文本。 請幫我解決這個問題。 這是我的QML代碼。
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
color: "#18d28a"
ColumnLayout{
id: base_coloumn_layout
width: parent.width
Layout.margins: 10
Text {
id: application_instruction
width: 640
text: qsTr("xyxvx dgdgdh dhdgdd dhdgdhhgd dhhhdgd dhdgdg dhdgdh djhddh djddgdhgdh dhdgdhgdgh dhgdgdhj dhdgdghdg dhjdgdgd.")
color: "#000000"
font.pointSize: 12
wrapMode: Text.WordWrap
}
}
}
放置在ColoumnLayout
外部時,相同的元素正常工作。 我可以將文本顯示為多行,代碼如下。 我想同樣的代碼應為兒童工作ColoumnLayout
一樣會有內部的幾個元素ColoumnLayout
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
color: "#18d28a"
Text {
id: application_instruction
width: 640
text: qsTr("xyxvx dgdgdh dhdgdd dhdgdhhgd dhhhdgd dhdgdg dhdgdh djhddh djddgdhgdh dhdgdhgdgh dhgdgdhj dhdgdghdg dhjdgdgd.")
color: "#000000"
font.pointSize: 12
wrapMode: Text.WordWrap
}
}
ColoumnLayout有什么問題。 我錯過了要設置的任何屬性值。 請幫忙
在ColumnLayout內部,將忽略width屬性。
而是設置Text元素的Layout.preferredWidth
或Layout.maximumWidth
附加屬性。
如果希望項目填充ColumnLayout的寬度,可以將Layout.fillWidth
附加屬性設置為true
。
從Mark給出的答案中,我們可以將qml更改為給定的下方,我們可以顯示多行文本。
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
id: application_window
visible: true
width: 640
height: 480
title: qsTr("Hello World")
color: "#18d28a"
ColumnLayout {
id: base_coloumn_layout
width: parent.width
Layout.margins: 10
Text {
id: application_instruction
width: application_window.width
Layout.preferredWidth: application_window.width
text: qsTr("xyxvx dgdgdh dhdgdd dhdgdhhgd dhhhdgd dhdgdg dhdgdh djhddh djddgdhgdh dhdgdhgdgh dhgdgdhj dhdgdghdg dhjdgdgd.")
color: "#000000"
font.pointSize: 12
wrapMode: Text.WordWrap
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.