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
5
#
include
"qquickbutton_p.h"
6
#
include
"qquickbutton_p_p.h"
7
8
#
include
<
QtGui
/
qpa
/
qplatformtheme
.
h
>
9
10
QT_BEGIN_NAMESPACE
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
23
Button presents a push-button control that can be pushed or clicked by
24
the user. Buttons are normally used to perform an action, or to answer
25
a question. Typical buttons are \e OK, \e Apply, \e Cancel, \e Close,
26
\e Yes, \e No, and \e Help.
27
28
Button inherits its API from AbstractButton. For instance, you can set
29
\l {AbstractButton::text}{text}, display an \l {Icons in Qt Quick Controls}{icon},
30
and react to \l {AbstractButton::clicked}{clicks} using the AbstractButton API.
31
32
A button emits the signal \l {AbstractButton::}{clicked()} when it is activated by the user.
33
Connect to this signal to perform the button's action. Buttons also
34
provide the signals \l {AbstractButton::}{canceled()}, \l {AbstractButton::}{doubleClicked()}, \l {AbstractButton::}{pressed()},
35
\l {AbstractButton::}{released()} and \l {AbstractButton::}{pressAndHold()} for long presses.
36
37
See the snippet below on how to connect to the button's signals.
38
39
\code
40
RowLayout {
41
Button {
42
text: "Ok"
43
onClicked: model.submit()
44
}
45
Button {
46
text: "Cancel"
47
onClicked: model.revert()
48
}
49
}
50
\endcode
51
52
\sa {Customizing Button}, {Button Controls}
53
*/
54
55
QQuickButton::QQuickButton(QQuickItem *parent)
56
: QQuickAbstractButton(*(
new
QQuickButtonPrivate), parent)
57
{
58
}
59
60
QQuickButton::QQuickButton(QQuickButtonPrivate &dd, QQuickItem *parent)
61
: QQuickAbstractButton(dd, parent)
62
{
63
}
64
65
QFont QQuickButton::defaultFont()
const
66
{
67
return
QQuickTheme::font(QQuickTheme::Button);
68
}
69
70
/*!
71
\qmlproperty bool QtQuick.Controls::Button::highlighted
72
73
This property holds whether the button is highlighted.
74
75
\image qtquickcontrols-button-highlighted.gif
76
77
A button can be highlighted in order to draw the user's attention towards
78
it. It has no effect on keyboard interaction.
79
80
The default value is \c false.
81
*/
82
bool
QQuickButton::isHighlighted()
const
83
{
84
Q_D(
const
QQuickButton);
85
return
d->highlighted;
86
}
87
88
void
QQuickButton::setHighlighted(
bool
highlighted)
89
{
90
Q_D(QQuickButton);
91
if
(highlighted == d->highlighted)
92
return
;
93
94
d->highlighted = highlighted;
95
emit highlightedChanged();
96
}
97
98
/*!
99
\qmlproperty bool QtQuick.Controls::Button::flat
100
101
This property holds whether the button is flat.
102
103
\image qtquickcontrols-button-flat.gif
104
105
A flat button typically does not draw a background unless it is pressed or checked.
106
107
The default value is \c false.
108
*/
109
bool
QQuickButton::isFlat()
const
110
{
111
Q_D(
const
QQuickButton);
112
return
d->flat;
113
}
114
115
void
QQuickButton::setFlat(
bool
flat)
116
{
117
Q_D(QQuickButton);
118
if
(flat == d->flat)
119
return
;
120
121
d->flat = flat;
122
emit flatChanged();
123
}
124
125
QPalette
QQuickButtonPrivate
::defaultPalette()
const
126
{
127
return
QQuickTheme::palette(QQuickTheme::Button);
128
}
129
130
QT_END_NAMESPACE
131
132
#
include
"moc_qquickbutton_p.cpp"
QQuickButtonPrivate
Definition
qquickbutton_p_p.h:24
QPlatformGraphicsBufferHelper
\inmodule QtGui
qtdeclarative
src
quicktemplates
qquickbutton.cpp
Generated on
for Qt by
1.14.0