Qt 在RowLayout中使用其他元素标记换行
在RowLayout中有两个元素,我试图将它们放在窗口的边界内Qt 在RowLayout中使用其他元素标记换行,qt,qml,Qt,Qml,在RowLayout中有两个元素,我试图将它们放在窗口的边界内 Page { id: settingsView anchors.fill: parent ColumnLayout { Layout.fillWidth: true RowLayout { Layout.fillWidth: true Label { text: "This is some
Page {
id: settingsView
anchors.fill: parent
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
Label {
text: "This is some long sample text which will definitely be wider than the page width."
padding: 6
Layout.maximumWidth: parent.width - timeComboBox.width
verticalAlignment: timeComboBox.height * 0.5
wrapMode: Label.WordWrap
}
ComboBox {
id: timeComboBox
model: ["1", "2", "3"]
}
}
}
}
此页面被推到StackView上(StackView也锚定.fill:parent),但无论我做什么,我都无法使标签文本被包装,组合框的一半在窗口边界之外。结果是答案非常简单,我所要做的就是删除
Layout.maximumWidth:parent.width-timeComboBox.width
,并将其替换为Layout.fillWidth:true
结果很简单,我所要做的就是删除Layout.maximumWidth:parent.width-timeComboBox.width
并将其替换为Layout.fillWidth:true
您有几个问题点,我已经纠正了一点:
页面{
id:设置视图
锚定。填充:父级
列布局{
宽度:parent.width//此项不在布局内,因此不能具有布局。*附加属性
行布局{
Layout.fillWidth:true
标签{
文本:“这是一个很长的示例文本,肯定会比页面宽度更宽。”
填充:10
Layout.fillWidth:true//只需填充组合框以外的所有空间即可
垂直对齐:Text.AlignVCenter//应为枚举,而不是数值
wrapMode:Text.WordWrap//这是Text.*emum,不是标签的
}
组合框{
id:timeComboBox
型号:[“1”、“2”、“3”]
}
}
}
}
您有几个问题点,我已经纠正了一些:
页面{
id:设置视图
锚定。填充:父级
列布局{
宽度:parent.width//此项不在布局内,因此不能具有布局。*附加属性
行布局{
Layout.fillWidth:true
标签{
文本:“这是一个很长的示例文本,肯定会比页面宽度更宽。”
填充:10
Layout.fillWidth:true//只需填充组合框以外的所有空间即可
垂直对齐:Text.AlignVCenter//应为枚举,而不是数值
wrapMode:Text.WordWrap//这是Text.*emum,不是标签的
}
组合框{
id:timeComboBox
型号:[“1”、“2”、“3”]
}
}
}
}