2

我正在尝试修改图库示例。我想ButtonTabView. 所以,我把TabViewButton放入ColumnLayout,这里是代码:

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

Window {
    visible: true
    title: "settings"
    width: 600
    height: 400
ColumnLayout{
    anchors.fill: parent
    TabView {
        anchors.right: parent.right
        anchors.left: parent.left
        Tab {
            title: "Controls"
            Controls { }
        }
        Tab {
            title: "Itemviews"
            Controls { }
        }
        Tab {
            title: "Styles"
            Controls {  }
        }
        Tab {
            title: "Layouts"
            Controls {  }
        }
    }

    RowLayout{
        anchors.right: parent.right
        anchors.left: parent.left
        Button{
            text: "ok"
        }
    }
}

}

但是,当我调整窗口大小时,它okButton位于选项卡控件下。我应该如何修复代码?

4

1 回答 1

1

定义 aLayout后,添加的每个元素都可以访问与布局本身相关的特定属性。这些属性对于将元素定位在布局覆盖的空间内很有用。面对这里描述的内容。

因此,您应该ColumnLayout像这样修改:

ColumnLayout {
    anchors.fill: parent                   
    TabView {
        id:frame
        enabled: enabledCheck.checked
        tabPosition: controlPage.item ? controlPage.item.tabPosition : Qt.TopEdge
        Layout.fillHeight: true            // fill the available space vertically 
        Layout.fillWidth: true             // fill the available space horizontally
        Layout.row: 0                      // item in the first row of the column
        anchors.margins: Qt.platform.os === "osx" ? 12 : 2
        Tab {
            id: controlPage
            title: "Controls"
            Controls { }
        }
        Tab {
            title: "Itemviews"
            ModelView { }
        }
        Tab {
            title: "Styles"
            Styles { anchors.fill: parent }
        }
        Tab {
            title: "Layouts"
            Layouts { anchors.fill:parent }
        }
    }

    Button {
        text: "ok"
        Layout.row: 1                       // item in the second row of the column
        Layout.alignment: Qt.AlignCenter    // simple center the button in its spatial slot
    }
}

您不需要 aRowLayout按钮。它应该放在ColumnLayout您定义的第二行,因为它是一个简单的组件。如果同一行上有多个元素,例如两个或多个按钮,则子布局可能很有用。

另请注意,锚定仅用于ColumnLayout“拉伸”并适合窗口。所有其他操作都通过布局属性执行。有关一般规则,请查看其他文章。

于 2014-11-22T10:06:04.667 回答