如何在QML中使用ColumnLayout中的topMargin

时间:2015-10-29 17:36:10

标签: qt qml

我正在尝试在ColumnLayout中使用topMargin。但我面临一些问题。 有人可以帮助我解决这个问题。

这是我的代码

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Layouts 1.1

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle{
        anchors.fill: parent
        ColumnLayout{
            id: columlayout
            Rectangle{
                width: 100
                height: 100
                color: "red"
            }
            Rectangle{
                Layout.topMargin: 50
                width: 100
                height: 100
                color: "green"
            }
            Rectangle{
                width: 100
                height: 100
                color: "blue"
            }
        }
    }
}

问题:

无法分配给不存在的属性" topMargin"

1 个答案:

答案 0 :(得分:1)

QtQuick.Layouts 1.2中引入了margin properties,因此您必须导入该版本,而不是1.1