本页内容

Button QML Type

可点击以执行命令或回答问题的按钮。更多...

Import Statement: import QtQuick.Controls
Inherits:

AbstractButton

Inherited By:

RoundButton and ToolButton

属性

详细说明

Button 提供了一种按钮控件,用户可以按下或单击它。按钮通常用于执行操作或回答问题。典型的按钮包括“确定”、“应用”、“取消”、“关闭”、“是”、“否”和“帮助”。

Button 继承了AbstractButton 的 API。例如,您可以使用AbstractButton API 设置text 、显示图标,并响应clicks 。

当按钮被用户激活时,会发出clicked()信号。订阅此信号以执行按钮的操作。此外,按钮还提供canceled()、doubleClicked()、pressed()、released()以及pressAndHold()等信号,用于处理长按操作。

请参阅下面的代码片段,了解如何连接按钮的信号。

RowLayout {
    Button {
        text: "Ok"
        onClicked: model.submit()
    }
    Button {
        text: "Cancel"
        onClicked: model.revert()
    }
}

另请参阅 《自定义 Button和Button 控件》。

属性文档

flat : bool

该属性用于指定按钮是否为平面样式。

一个标签为“Button”的按钮,采用扁平化风格,无背景

通常情况下,平铺按钮不会绘制背景,除非被按下或选中。

默认值为false 。

highlighted : bool

无论按钮是否处于高亮状态,此属性均有效。

带有视觉强调效果的高亮按钮

按钮可以被高亮显示,以吸引用户的注意力。这不会影响键盘交互。

默认值为false 。

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