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
qquickradiodelegate.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
"qquickradiodelegate_p.h"
6
#
include
"qquickabstractbutton_p_p.h"
7
#
include
"qquickitemdelegate_p_p.h"
8
9
#
include
<
QtGui
/
qpa
/
qplatformtheme
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
/*!
14
\qmltype RadioDelegate
15
\inherits ItemDelegate
16
//! \nativetype QQuickRadioDelegate
17
\inqmlmodule QtQuick.Controls
18
\since 5.7
19
\ingroup qtquickcontrols-delegates
20
\brief Exclusive item delegate with a radio indicator that can be toggled on or off.
21
22
\image qtquickcontrols-radiodelegate.gif
23
{Radio delegates showing exclusive selection behavior}
24
25
RadioDelegate presents an item delegate that can be toggled on (checked) or
26
off (unchecked). Radio delegates are typically used to select one option
27
from a set of options.
28
29
RadioDelegate inherits its API from \l ItemDelegate, which is inherited
30
from AbstractButton. For instance, you can set \l {AbstractButton::text}{text},
31
and react to \l {AbstractButton::clicked}{clicks} using the AbstractButton
32
API. The state of the radio delegate can be set with the
33
\l {AbstractButton::}{checked} property.
34
35
Radio delegates are \l {AbstractButton::autoExclusive}{auto-exclusive}
36
by default. Only one delegate can be checked at any time amongst radio
37
delegates that belong to the same parent item; checking another delegate
38
automatically unchecks the previously checked one. For radio delegates
39
that do not share a common parent, ButtonGroup can be used to manage
40
exclusivity.
41
42
\l RadioButton is similar to RadioDelegate, except that it is typically
43
not used in views, but rather when there are only a few options, and often
44
with the requirement that each button is uniquely identifiable.
45
46
\code
47
ButtonGroup {
48
id: buttonGroup
49
}
50
51
ListView {
52
model: ["Option 1", "Option 2", "Option 3"]
53
delegate: RadioDelegate {
54
text: modelData
55
checked: index == 0
56
ButtonGroup.group: buttonGroup
57
}
58
}
59
\endcode
60
61
\sa {Customizing RadioDelegate}, {Delegate Controls}, RadioButton
62
*/
63
64
class
Q_QUICKTEMPLATES2_EXPORT
QQuickRadioDelegatePrivate
:
public
QQuickItemDelegatePrivate
65
{
66
Q_DECLARE_PUBLIC(QQuickRadioDelegate)
67
68
public
:
69
QPalette defaultPalette()
const
override {
return
QQuickTheme::palette(QQuickTheme::ListView); }
70
};
71
72
QQuickRadioDelegate::QQuickRadioDelegate(QQuickItem *parent)
73
: QQuickItemDelegate(*(
new
QQuickRadioDelegatePrivate), parent)
74
{
75
setCheckable(
true
);
76
setAutoExclusive(
true
);
77
}
78
79
QFont QQuickRadioDelegate::defaultFont()
const
80
{
81
return
QQuickTheme::font(QQuickTheme::ListView);
82
}
83
84
#
if
QT_CONFIG
(
accessibility
)
85
QAccessible::Role QQuickRadioDelegate::accessibleRole()
const
86
{
87
return
QAccessible::RadioButton;
88
}
89
#
endif
90
91
QT_END_NAMESPACE
92
93
#
include
"moc_qquickradiodelegate_p.cpp"
QQuickRadioDelegatePrivate
Exclusive item delegate with a radio indicator that can be toggled on or off.
Definition
qquickradiodelegate.cpp:65
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qrandomaccessasyncfile_darwin.mm:17
qtdeclarative
src
quicktemplates
qquickradiodelegate.cpp
Generated on
for Qt by
1.16.1