Qt Text.wordWrap设置为Text.Wrap不会更新Text.lineCount
我正在使用,基于,并尝试在运行时根据其子对象的文本大小设置父对象的宽度: 现在,一切正常,但是,最后一个对象是2行,因为它的长度,这是确定的。但是,不会更新为2(两行),但会返回1(一行)。为什么以及如何计算包裹的线条 附录A: 我已将包含信息文本的对象从更改为: 现在第三个是在屏幕上显示两行: 但是,Qt Text.wordWrap设置为Text.Wrap不会更新Text.lineCount,qt,qml,qt5,Qt,Qml,Qt5,我正在使用,基于,并尝试在运行时根据其子对象的文本大小设置父对象的宽度: 现在,一切正常,但是,最后一个对象是2行,因为它的长度,这是确定的。但是,不会更新为2(两行),但会返回1(一行)。为什么以及如何计算包裹的线条 附录A: 我已将包含信息文本的对象从更改为: 现在第三个是在屏幕上显示两行: 但是,ticketRouteTextValueEN.lineCount返回5(5行),这是不正常的。它应该返回2,因此,的内容太复杂。为什么会这样 import QtQuick 2.13 import
ticketRouteTextValueEN.lineCount
返回5(5行),这是不正常的。它应该返回2,因此,的内容太复杂。为什么会这样
import QtQuick 2.13
import QtQuick.Window 2.13
import QtQuick.Layouts 1.12
Window
{
id: mainWindow
property real ticketHeight: 0.00
function printHeight()
{
console.log("[QML]"+
" "+
"Layout height:"+
" "+
mainLayout.height);
console.log("[QML]"+
" "+
"ticketHeight:"+
" "+
mainWindow.ticketHeight);
console.log("[QML]"+
" "+
"Layout implicit height:"+
" "+
mainLayout.implicitHeight);
} // printHeight
visible: true
width: 560
height: ticketHeight
title: qsTr("Hello World")
ColumnLayout
{
id: mainLayout
anchors.fill: parent
Rectangle
{
id: mainRectangle
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
ColumnLayout
{
id: contentLayout
anchors.fill: parent
RowLayout
{
id: ticketTypeLayout
property bool heightAlreadyAdded: false
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
Text
{
id: ticketTypeTextValueEN
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignLeft|Qt.AlignTop
font.pointSize: 32
text: "Adult"
onTextChanged:
{
if(ticketTypeLayout.heightAlreadyAdded===false)
{
mainWindow.ticketHeight+=ticketTypeTextValueEN.height+
ticketTypeLayout.spacing;
ticketTypeLayout.heightAlreadyAdded=true;
} // if
} // onTextChanged
Component.onCompleted:
{
mainWindow.ticketHeight+=ticketTypeTextValueEN.height+
ticketTypeLayout.spacing;
console.log("ticketTypeTextValueEN.height:"+
" "+
ticketTypeTextValueEN.height);
} // Component.onCompleted
} // ticketTypeTextValue (Text)
Text
{
id: ticketTypeTextValueAR
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignRight|Qt.AlignTop
font.family: arabicFont.name
font.pointSize: 32
text: "بالغ"
} // ticketTypeTextValueAR (Text)
} // ticketTypeLayout (RowLayout)
RowLayout
{
id: ticketZoneLayout
property bool heightAlreadyAdded: false
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
Text
{
id: ticketZoneTextValueEN
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignLeft|Qt.AlignTop
font.pointSize: 32
text: "Zone 1"
onTextChanged:
{
if(ticketZoneLayout.heightAlreadyAdded===false)
{
mainWindow.ticketHeight+=ticketZoneTextValueEN.height+
ticketZoneLayout.spacing;
ticketZoneLayout.heightAlreadyAdded=true;
} // if
} // onTextChanged
Component.onCompleted:
{
mainWindow.ticketHeight+=ticketZoneTextValueEN.height+
ticketZoneLayout.spacing;
console.log("ticketZoneTextValueEN.height:"+
" "+
ticketZoneTextValueEN.height);
} // Component.onCompleted
} // ticketZoneTextValueEN (Text)
Text
{
id: ticketZoneTextValueAR
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignRight|Qt.AlignTop
font.family: arabicFont.name
font.pointSize: 32
text: "لمنطقة 1"
} // ticketZoneTextValueAR (Text)
} // ticketTypeLayout (RowLayout)
RowLayout
{
id: ticketRouteLayout
property bool heightAlreadyAdded: false
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
Text
{
id: ticketRouteTextValueEN
objectName: "ticketRouteTextValueEN"
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignLeft|Qt.AlignTop
wrapMode: Text.Wrap
font.pointSize: 32
text: "Mwsalat bus station 1"
onTextChanged:
{
if(ticketRouteLayout.heightAlreadyAdded===false)
{
mainWindow.ticketHeight+=ticketRouteTextValueEN.height+
ticketRouteLayout.spacing;
ticketRouteLayout.heightAlreadyAdded=true;
console.log("ticketRouteTextValueEN.height:"+
" "+
ticketRouteTextValueEN.height+
" "+
"ticketRouteTextValueEN.lineCount:"+
" "+
ticketRouteTextValueEN.lineCount);
} // if
} // onTextChanged
Component.onCompleted:
{
ticketRouteTextValueEN.height
mainWindow.ticketHeight+=ticketRouteTextValueEN.height+
ticketRouteLayout.spacing;
console.log("ticketRouteTextValueEN.height:"+
" "+
ticketRouteTextValueEN.height+
" "+
"ticketRouteTextValueEN.lineCount:"+
" "+
ticketRouteTextValueEN.lineCount);
} // Component.onCompleted
} // ticketRouteTextValueEN (Text)
Text
{
id: ticketRouteTextValueAR
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignRight|Qt.AlignTop
wrapMode: Text.Wrap
font.family: arabicFont.name
font.pointSize: 32
text: "محطة حافلات موصلات 1"
} // ticketRouteTextValueAR (Text)
} // ticketTypeLayout (RowLayout)
} // contentLayout (ColumnLayout)
} // mainRectangle
Component.onCompleted:
{
} // Component.onCompleted
onHeightChanged:
{
mainWindow.printHeight();
} // onHeightChanged
} // mainLayout (ColumnLayout)
FontLoader
{
id: arabicFont
source: "qrc:/fonts/NotoNaskhArabic-Regular.ttf"
} // arabicFont (FontLoader)
} // mainWindow (Window)
/*##^##
Designer {
D{i:0;height:237;width:560}
}
##^##*/
import QtQuick 2.13
import QtQuick.Window 2.13
import QtQuick.Layouts 1.12
Window
{
id: mainWindow
property real ticketHeight: 0.00
function printHeight()
{
console.log("[QML]"+
" "+
"Layout height:"+
" "+
mainLayout.height);
console.log("[QML]"+
" "+
"ticketHeight:"+
" "+
mainWindow.ticketHeight);
console.log("[QML]"+
" "+
"Layout implicit height:"+
" "+
mainLayout.implicitHeight);
} // printHeight
visible: true
width: 560
height: ticketHeight
title: qsTr("Hello World")
ColumnLayout
{
id: mainLayout
anchors.fill: parent
Rectangle
{
id: mainRectangle
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
ColumnLayout
{
id: contentLayout
anchors.fill: parent
RowLayout
{
id: ticketTypeLayout
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
TextEdit
{
id: ticketTypeTextValueEN
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
readOnly: true
selectByKeyboard: false
selectByMouse: false
wrapMode: Text.Wrap
font.pointSize: 32
text: "Adult"
Component.onCompleted:
{
mainWindow.ticketHeight+=ticketTypeTextValueEN.lineCount*
ticketTypeTextValueEN.height+
ticketTypeLayout.spacing;
} // Component.onCompleted
} // ticketTypeTextValue (TextEdit)
TextEdit
{
id: ticketTypeTextValueAR
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignRight|Qt.AlignVCenter
readOnly: true
selectByKeyboard: false
selectByMouse: false
wrapMode: Text.Wrap
font.family: arabicFont.name
font.pointSize: 32
text: "بالغ"
} // ticketTypeTextValueAR (TextEdit)
} // ticketTypeLayout (RowLayout)
RowLayout
{
id: ticketZoneLayout
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
TextEdit
{
id: ticketZoneTextValueEN
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
readOnly: true
selectByKeyboard: false
selectByMouse: false
wrapMode: Text.Wrap
font.pointSize: 32
text: "Zone 1"
Component.onCompleted:
{
mainWindow.ticketHeight+=ticketZoneTextValueEN.lineCount*
ticketZoneTextValueEN.height/*+
ticketZoneLayout.spacing;*/
} // Component.onCompleted
} // ticketZoneTextValueEN (TextEdit)
TextEdit
{
id: ticketZoneTextValueAR
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignRight|Qt.AlignVCenter
readOnly: true
selectByKeyboard: false
selectByMouse: false
wrapMode: Text.Wrap
font.family: arabicFont.name
font.pointSize: 32
text: "لمنطقة 1"
} // ticketZoneTextValueAR (TextEdit)
} // ticketTypeLayout (RowLayout)
RowLayout
{
id: ticketRouteLayout
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
TextEdit
{
id: ticketRouteTextValueEN
objectName: "ticketRouteTextValueEN"
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignLeft|Qt.AlignVCenter
readOnly: true
selectByKeyboard: false
selectByMouse: false
wrapMode: Text.Wrap
font.pointSize: 32
text: "Mwsalat bus station 1"
Component.onCompleted:
{
mainWindow.ticketHeight+=ticketRouteTextValueEN.lineCount*
ticketRouteTextValueEN.height+
ticketRouteLayout.spacing;
} // Component.onCompleted
} // ticketRouteTextValueEN (TextEdit)
TextEdit
{
id: ticketRouteTextValueAR
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignRight|Qt.AlignVCenter
readOnly: true
selectByKeyboard: false
selectByMouse: false
wrapMode: Text.Wrap
font.family: arabicFont.name
font.pointSize: 32
text: "محطة حافلات موصلات 1"
} // ticketRouteTextValueAR (TextEdit)
} // ticketTypeLayout (RowLayout)
} // contentLayout (ColumnLayout)
} // mainRectangle
onHeightChanged:
{
mainWindow.printHeight();
} // onHeightChanged
} // mainLayout (ColumnLayout)
FontLoader
{
id: arabicFont
source: "qrc:/fonts/NotoNaskhArabic-Regular.ttf"
} // arabicFont (FontLoader)
} // mainWindow (Window)
/*##^##
Designer {
D{i:0;height:237;width:560}
}
##^##*/