gpt4 book ai didi

qt - 对齐以右对齐 RowLayout 中的项目

转载 作者:行者123 更新时间:2023-12-02 20:11:27 25 4
gpt4 key购买 nike

我想将 RowLayout 中的最后一个项目右对齐,但即使 RowLayout 的宽度大于所有子项的宽度,该项目仍紧跟在其他项目之后。如果我使用 anchors.right:parent.right 它运行良好,但随后我收到警告。

ToolBar {
height: globals.toolBar.height
width:parent.width
background: Rectangle {
anchors.fill: parent
color:"white"
}

RowLayout {
id: row
anchors.fill: parent

Button{
Layout.alignment: Qt.AlignLeft
contentItem: Image {
source: "images/iconmenu.png"
}
}
Button {
Layout.alignment: Qt.AlignLeft
contentItem: Image {
source: "images/iconget.png"
}
ToolTip.text: qsTr("Get Data from Panel")
ToolTip.visible: hovered
}
Button {
id:buttonAbout
Layout.alignment:Qt.AlignRight
font.family: fontAwesomeSolid.font
width:15
height: 15
text: "\uf129"
ToolTip.text:qsTr("about")
ToolTip.visible: hovered
contentItem: Text {
anchors.fill:buttonAbout
anchors.right:buttonAbout.right
anchors.topMargin: 3
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCente
text: buttonAbout.text
}
background:
Rectangle{
width:20
height: 20
anchors.right: parent.right
anchors.topMargin: 20
radius:10
border.width: 1
border.color:"gray"
}
onClicked: popup.open()
}
Item {
Layout.fillWidth: true
}
}
}

| |第 1 项| |第 2 项 | |第 3 项 | ------------------ |

我要的是这个


| |第 1 项| |项目 2 |--------------------|第 3 项 ||

最佳答案

Row 和 RowLayout 似乎不会让空白空间那样存在。但是可以使用执行 fillwidth:true 的组件来解决

    Item{
Layout.fillWidth: true
height: buttonAbout.implicitHeight
Button{
id:buttonAbout
}
}

关于qt - 对齐以右对齐 RowLayout 中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53538518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com