Button QML Type

按钮,点击后可执行命令或回答问题。更多

Import Statement: import QtQuick.Controls
Inherits:

AbstractButton

Inherited By:

RoundButton and ToolButton

属性

详细说明

按钮(Button)是一个按钮控件,用户可以按下或点击它。按钮通常用于执行操作或回答问题。典型的按钮有确定应用取消关闭是、 帮助

按钮的 API 继承自AbstractButton 。例如,您可以使用AbstractButton API 设置text 、显示图标并对clicks 做出反应。

当用户激活按钮时,按钮会发出信号clicked() 。连接到该信号可执行按钮的操作。按钮还提供用于长按的信号canceled(),doubleClicked(),pressed(),released() 和pressAndHold() 。

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

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

另请参阅 自定义按钮按钮控件

属性文档

flat : bool

该属性表示按钮是否为平面按钮。

除非按下或选中,否则平面按钮通常不会绘制背景。

默认值为false


highlighted : bool

该属性显示按钮是否高亮显示。

按钮可以高亮显示,以吸引用户注意。它对键盘交互没有影响。

默认值为false


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