Qt Quick Controls QML Types

Qt Quick Controls提供了用于创建用户界面的 QML 类型。这些 QML 类型与 Qt QuickQt Quick Layouts 配合使用

Qt Quick Controls 可在 .qml 文件中使用以下导入语句将 QML 类型导入应用程序:

import QtQuick.Controls

QML 类型

AbstractButton

提供按钮通用功能的抽象基本类型

Action

抽象用户界面操作

ActionGroup

将操作组合在一起

ApplicationWindow

风格化的顶层窗口,支持页眉和页脚

BusyIndicator

表示后台活动,例如正在加载内容时

Button

可点击执行命令或回答问题的按钮

ButtonGroup

互斥的可选中按钮组

Calendar

日历命名空间

CalendarModel

日历模型

CheckBox

可打开或关闭的复选按钮

CheckDelegate

带有可打开或关闭复选指示器的项目委托

ComboBox

用于选择选项的组合按钮和弹出列表

Container

抽象基本类型,提供容器的通用功能

ContextMenu

附加类型提供了一种以适合平台的方式打开上下文菜单的方法

Control

抽象基本类型,提供所有控件的通用功能

DayOfWeekRow

一排表示一周内天数的名称

DelayButton

按住足够长的时间就会触发的复选按钮

Dial

圆形刻度盘,旋转后可设置数值

Dialog

弹出式对话框,带有标准按钮和标题,用于与用户进行短期交互

DialogButtonBox

对话框中使用的按钮框

Drawer

可通过轻扫手势打开和关闭的侧边面板

Frame

逻辑控件组的视觉框架

GroupBox

逻辑控件组的视觉框架和标题

HorizontalHeaderView

为 TableView 提供水平标题视图

ItemDelegate

可在各种视图和控件中使用的基本项目委托

Label

具有继承字体的样式文本标签

Menu

可用作上下文菜单或弹出菜单的弹出窗口

MenuBar

提供窗口菜单栏

MenuBarItem

在菜单栏中显示下拉菜单

MenuItem

在菜单中显示一个项目

MenuSeparator

将菜单中的一组项目与相邻项目分开

MonthGrid

日历月的天数网格

Overlay

弹出窗口覆盖

Page

支持页眉和页脚的样式页面控件

PageIndicator

显示当前活动页面

Pane

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

Popup

弹出式用户界面控件的基本类型

ProgressBar

显示操作进度

RadioButton

可打开或关闭的专用单选按钮

RadioDelegate

带有可打开或关闭的单选指示器的专属项目委托

RangeSlider

通过沿轨道滑动两个手柄来选择数值范围

RoundButton

用户可点击的圆角按钮控件

ScrollBar

垂直或水平交互式滚动条

ScrollIndicator

垂直或水平非交互式滚动指示器

ScrollView

可滚动视图

SelectionRectangle

用于在 TableView 中选择表格单元格

Slider

用于通过沿轨道滑动手柄来选择数值

SpinBox

允许用户从一组预设值中进行选择

SplitHandle

为 SplitView 控件提供附加属性

SplitView

在每个项目之间使用可拖动的分割器排列项目

StackView

提供基于堆栈的导航模型

SwipeDelegate

可轻扫的项目委托

SwipeView

使用户能够通过横向滑动来导航页面

Switch

可打开或关闭的按钮

SwitchDelegate

带有开关指示器的项目委托,可打开或关闭

TabBar

允许用户在不同视图或子任务之间切换

TabButton

外观适合 TabBar 的按钮

TableViewDelegate

可分配给 TableView 的委托

TextArea

多行文本输入区

TextField

单行文本输入框

ToolBar

上下文相关控件的容器

ToolButton

具有适合工具栏外观的按钮

ToolSeparator

将工具栏中的一组项目与相邻项目分开

ToolTip

为任何控件提供工具提示

TreeViewDelegate

可分配给树形视图的委托

Tumbler

可选择项目的可旋转滚轮

VerticalHeaderView

为表格视图提供垂直标题视图

WeekNumberColumn

一列周数

在属性声明中使用Qt Quick Controls 类型

中提到的 Qt Quick Templates 2 QML Types中提到,Qt Quick Controls 中的每种类型都由 C++"模板 "类型支持。这些类型是控件逻辑和行为的非可视化实现

例如,Menu 类型的 API 和行为是由Qt Quick Templates 中的 C++ 类型定义的。每个想要提供菜单的样式都必须有一个可用的 Menu.qml,该文件的根项必须是Qt Quick Templates 中的菜单。当你导入QtQuick.Controls 并用 QML 创建菜单时,你得到的类型实际上是由样式的 Menu.qml 定义的 QML 菜单。

要在属性声明中使用控件作为类型,应使用Qt Quick Templates 中的相应类型。例如,假设你有一个PopupOpener 组件,它是一个打开弹出窗口的按钮:

// PopupButton.qml
import QtQuick.Controls

Button {
    required property Popup popup

    onClicked: popup.open()
}

// main.qml
PopupButton {
    popup: saveChangesDialog
}

Dialog {
    id: saveChangesDialog

    // ...
}

运行这段代码将导致错误:

Unable to assign Dialog_QMLTYPE to Popup_QMLTYPE

这是由于继承层次结构造成的:

Popup (C++ type in QtQuick.Templates)
│   └── Popup (QML type in QtQuick.Controls)
└── Dialog (C++ type in QtQuick.Templates)
    └── Dialog (QML type in QtQuick.Controls)

QtQuick.Controls 中的 Dialog 并不是从QtQuick.Controls 中的 Popup 派生的,而是从QtQuick.Templates 派生的。

请使用Qt Quick Templates 中的 Popup 作为属性类型:

// PopupButton.qml
import QtQuick.Controls
import QtQuick.Templates as T

Button {
    required property T.Popup popup

    onClicked: popup.open()
}

有关Qt Quick Controls 模块的更多信息,请参阅 Qt Quick Controls模块文档。

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