ColumnLayout中的QML选项卡视图

ColumnLayout中的QML选项卡视图,qml,qtquickcontrols,Qml,Qtquickcontrols,我试图修改画廊的例子。我想在选项卡视图下添加按钮。因此,我将选项卡视图和按钮放入列布局,下面是代码: 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

我试图修改画廊的例子。我想在
选项卡视图下添加
按钮
。因此,我将
选项卡视图
按钮
放入
列布局
,下面是代码:

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"
        }
    }
}

}

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

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

因此,您应该修改
列布局
,如下所示:

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


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

如我所见,您将按钮放在TabView下,那么您的问题是什么?我无法测试您的示例,只是因为
控件
,但可能您应该为
选项卡
使用
Layout.fillHeight
&
Layout.fillWidth
?但别忘了设定高度RowLayout@folibis
Controls.qml
位于
Qt快速控制库中
示例。只需打开Qt creator->欢迎并键入“Gallery”。当我调整窗口大小时,
ok按钮
不在
TabView
下,而是在
TabView
上。当我调整窗口大小时,
ok按钮
放在TabView控件的上方。如果您以gallery示例为例,按照我的方式更改代码,则不应该这样做。如果删除了可能的最小宽度:这取决于选项卡组件的设置。这是一个完全不同的问题。实际上,
控件
具有
布局。最小宽度:隐式宽度
。。。你不能只调整
窗口的大小而不考虑组件的布局。我增加了最小宽度和高度。现在它工作得很好,就是这样。:)我建议你阅读我提供的链接。他们会澄清你的任何疑问。