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