【问题标题】:How to center elements in ColumnLayout如何在 ColumnLayout 中将元素居中
【发布时间】:2017-03-22 18:25:07
【问题描述】:

如何在ColumnLayout 中居中元素?

这是我的 qml 代码:

ApplicationWindow {
    id: root
    visible: true
    width: 640
    height: 640
    title: qsTr("Your Booking")
    GridLayout{
        anchors.fill: parent
        columns: 2
        flow: GridLayout.TopToBottom
        Rectangle{
            id: appBar
            Layout.columnSpan: 2
            width: root.width
            height: root.height/10
            color: "red"
        }
        ColumnLayout{
            spacing:5
            id: columnData
            height: root.height - appBar.height
            width: root.width/2

            ComboBox{
                 anchors.horizontalCenter: parent.horizontalCenter
            }
            ComboBox{

            }
            ComboBox{
            }
            ComboBox{
            }
            ComboBox{
            }
        }
        ColumnLayout{

        }

    }
}

我想在 ColumnLayout 中居中组合框。

【问题讨论】:

    标签: qt qtquick2


    【解决方案1】:

    您应该避免同时使用锚点和布局。将它们混合在同一级别会导致布局故障或一些意想不到的结果(但是,在布局中的项目内使用锚点是可以的)。

    要对齐布局中的项目,您可以使用附加属性:Layout.alignment,例如:

     Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
    

    此语句将使您的项目完全位于布局的中心。

    【讨论】:

    猜你喜欢
    • 2018-12-02
    • 2023-03-29
    • 2022-08-21
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-06
    相关资源
    最近更新 更多