本页内容

Pane QML Type

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

Import Statement: import QtQuick.Controls
Inherits:

Control

Inherited By:

Frame, GroupBox, Page, ScrollView, and ToolBar

属性

详细说明

Pane 提供与应用程序样式和主题相匹配的背景颜色。Pane 本身不提供布局,而是需要您手动定位其内容,例如通过创建RowLayout 或ColumnLayout 来实现。

作为 Pane 子元素声明的项目会自动归属于该 Pane 的contentItem 。动态创建的项目需要显式地归属于contentItem 。

如Event Handling 中所述,Pane不会将点击和触摸事件传递给其下方的项目。如果wheelEnabled 为true ,则鼠标滚轮事件也同样如此。

内容尺寸调整

如果 Pane 中仅包含一个项目,它会自动调整大小以适应所包含项目的隐式尺寸。这使其特别适合与布局配合使用。

包含复选框且具有样式化背景的窗格

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

有时 Pane 中可能包含两个项目:

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会采用Rectangle的大小:

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

另请参阅 《自定义 Pane》、《容器控件》、《 Qt Quick Controls 中的焦点管理》以及《Event Handling 》。

属性文档

contentChildren : list<Item>

该属性保存内容子节点的列表。

该列表包含所有在 QML 中被声明为该面板子节点的项目。

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

另请参阅 Item::children 和contentData 。

contentData : list<QtObject> [default]

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

该列表包含所有在 QML 中被声明为该面板子元素的对象。

注意:与 `contentChildren`不同 ,`contentData ` 确实包含非视觉 QML 对象。

另请参阅 Item::data 和contentChildren 。

contentHeight : real

该属性存储内容高度,用于计算窗格的总隐式高度。

有关详细信息,请参阅Content Sizing 。

另请参阅 contentWidth 。

contentWidth : real

该属性存储内容宽度,用于计算窗格的总隐式宽度。

有关详细信息,请参阅Content Sizing 。

另请参阅 contentHeight 。

© 2026 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.