Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickbutton.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7
8#include <QtGui/qpa/qplatformtheme.h>
9
11
12/*!
13 \qmltype Button
14 \inherits AbstractButton
15//! \nativetype QQuickButton
16 \inqmlmodule QtQuick.Controls
17 \since 5.7
18 \ingroup qtquickcontrols-buttons
19 \brief Push-button that can be clicked to perform a command or answer a question.
20
21 \image qtquickcontrols-button.gif
22 {Button control in various interaction states}
23
24 Button presents a push-button control that can be pushed or clicked by
25 the user. Buttons are normally used to perform an action, or to answer
26 a question. Typical buttons are \e OK, \e Apply, \e Cancel, \e Close,
27 \e Yes, \e No, and \e Help.
28
29 Button inherits its API from AbstractButton. For instance, you can set
30 \l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls}{icon},
31 and react to \l {AbstractButton::clicked}{clicks} using the AbstractButton API.
32
33 A button emits the signal \l {AbstractButton::}{clicked()} when it is activated by the user.
34 Connect to this signal to perform the button's action. Buttons also
35 provide the signals \l {AbstractButton::}{canceled()}, \l {AbstractButton::}{doubleClicked()}, \l {AbstractButton::}{pressed()},
36 \l {AbstractButton::}{released()} and \l {AbstractButton::}{pressAndHold()} for long presses.
37
38 See the snippet below on how to connect to the button's signals.
39
40 \code
41 RowLayout {
42 Button {
43 text: "Ok"
44 onClicked: model.submit()
45 }
46 Button {
47 text: "Cancel"
48 onClicked: model.revert()
49 }
50 }
51 \endcode
52
53 \sa {Customizing Button}, {Button Controls}
54*/
55
56QQuickButton::QQuickButton(QQuickItem *parent)
57 : QQuickAbstractButton(*(new QQuickButtonPrivate), parent)
58{
59}
60
61QQuickButton::QQuickButton(QQuickButtonPrivate &dd, QQuickItem *parent)
62 : QQuickAbstractButton(dd, parent)
63{
64}
65
66QFont QQuickButton::defaultFont() const
67{
68 return QQuickTheme::font(QQuickTheme::Button);
69}
70
71/*!
72 \qmlproperty bool QtQuick.Controls::Button::highlighted
73
74 This property holds whether the button is highlighted.
75
76 \image qtquickcontrols-button-highlighted.gif
77 {Highlighted button showing visual emphasis}
78
79 A button can be highlighted in order to draw the user's attention towards
80 it. It has no effect on keyboard interaction.
81
82 The default value is \c false.
83*/
84bool QQuickButton::isHighlighted() const
85{
86 Q_D(const QQuickButton);
87 return d->highlighted;
88}
89
90void QQuickButton::setHighlighted(bool highlighted)
91{
92 Q_D(QQuickButton);
93 if (highlighted == d->highlighted)
94 return;
95
96 d->highlighted = highlighted;
97 emit highlightedChanged();
98}
99
100/*!
101 \qmlproperty bool QtQuick.Controls::Button::flat
102
103 This property holds whether the button is flat.
104
105 \image qtquickcontrols-button-flat.gif
106 {Button labeled "Button" in flat style with no background}
107
108 A flat button typically does not draw a background unless it is pressed or checked.
109
110 The default value is \c false.
111*/
112bool QQuickButton::isFlat() const
113{
114 Q_D(const QQuickButton);
115 return d->flat;
116}
117
118void QQuickButton::setFlat(bool flat)
119{
120 Q_D(QQuickButton);
121 if (flat == d->flat)
122 return;
123
124 d->flat = flat;
125 emit flatChanged();
126}
127
128QPalette QQuickButtonPrivate::defaultPalette() const
129{
130 return QQuickTheme::palette(QQuickTheme::Button);
131}
132
133QT_END_NAMESPACE
134
135#include "moc_qquickbutton_p.cpp"
Combined button and popup list for selecting options.