右对齐 RowLayout 内的项目

Nma*_*r88 2 qt qml

我想将 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
    }
}
}
Run Code Online (Sandbox Code Playgroud)

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

我想要的是这个


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

Nma*_*r88 5

看来 Row 和 RowLayout 不允许这样的空白存在。但可以使用执行 fillwidth:true 的组件来解决

    Item{
        Layout.fillWidth: true
        height: buttonAbout.implicitHeight
        Button{
            id:buttonAbout
}
}
Run Code Online (Sandbox Code Playgroud)