Pane QML Type

提供与应用程序风格和主题相匹配的背景。更多

Import Statement: import QtQuick.Controls
Inherits:

Control

Inherited By:

Frame, Page, ScrollView, and ToolBar

属性

详细说明

Pane 提供与应用程序风格和主题相匹配的背景颜色。窗格本身不提供布局,但需要您对其内容进行定位,例如通过创建RowLayoutColumnLayout

声明为 Pane 子项的项目会自动以 Pane 的contentItem 为父级。动态创建的项目需要明确以contentItem 为父级。

Event Handling 所述,Pane 不会让点击和触摸事件传递到其下的项目。如果wheelEnabledtrue ,鼠标滚轮事件也是如此。

内容大小

如果窗格中只使用了一个项目,它将调整大小以适应其所包含项目的隐式大小。这使其特别适合与布局一起使用。

Pane {
    ColumnLayout {
        anchors.fill: parent
        CheckBox { text: qsTr("E-mail") }
        CheckBox { text: qsTr("Calendar") }
        CheckBox { text: qsTr("Contacts") }
    }
}

有时,窗格中可能包含两个项目:

Pane {
    SwipeView {
        // ...
    }
    PageIndicator {
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottom: parent.bottom
    }
}

在这种情况下,Pane 无法计算出合理的隐式尺寸。由于我们将PageIndicator 锚定在SwipeView 上,因此可以简单地将内容大小设置为视图的隐式大小:

Pane {
    contentWidth: view.implicitWidth
    contentHeight: view.implicitHeight

    SwipeView {
        id: view
        // ...
    }
    PageIndicator {
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottom: parent.bottom
    }
 }

如果contentItem 没有隐式大小,只有一个子视图,Pane 将使用该子视图的隐式大小。例如,在以下代码中,Pane 将使用矩形的大小:

Pane {
    Item {
        Rectangle {
            implicitWidth: 200
            implicitHeight: 200
            color: "salmon"
        }
    }
}

另请参阅 自定义窗格容器控件 Qt Quick Controls 中的焦点管理Event Handling

属性文档

contentChildren : list<Item>

该属性包含内容子项列表。

该列表包含在 QML 中声明为窗格子项的所有项目。

注意: contentData 不同,contentChildren 不包括非可视 QML 对象。

另请参阅 Item::childrencontentData


contentData : list<QtObject> [default]

该属性包含内容数据列表。

该列表包含在 QML 中声明为窗格子对象的所有对象。

注意: contentChildren 不同,contentData 包含非可视 QML 对象。

另请参阅 Item::datacontentChildren


contentHeight : real

该属性包含内容高度。它用于计算窗格的总隐含高度。

更多信息,请参阅Content Sizing

另请参阅 contentWidth


contentWidth : real

该属性表示内容宽度。用于计算窗格的总隐含宽度。

更多信息,请参阅Content Sizing

另请参见 contentHeight


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.