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
qquickradiobutton.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 RadioButton
15 \inherits AbstractButton
16//! \nativetype QQuickRadioButton
17 \inqmlmodule QtQuick.Controls
18 \since 5.7
19 \ingroup qtquickcontrols-buttons
20 \brief Exclusive radio button that can be toggled on or off.
21
22 \image qtquickcontrols-radiobutton.gif
23
24 RadioButton presents an option button that can be toggled on (checked) or
25 off (unchecked). Radio buttons are typically used to select one option
26 from a set of options.
27
28 RadioButton inherits its API from \l AbstractButton. For instance,
29 you can set \l {AbstractButton::text}{text} and react to
30 \l {AbstractButton::clicked}{clicks} using the AbstractButton API.
31 The state of the radio button can be set with the
32 \l {AbstractButton::}{checked} property.
33
34 Radio buttons are \l {AbstractButton::autoExclusive}{auto-exclusive}
35 by default. Only one button can be checked at any time amongst radio
36 buttons that belong to the same parent item; checking another button
37 automatically unchecks the previously checked one. For radio buttons
38 that do not share a common parent, ButtonGroup can be used to manage
39 exclusivity.
40
41 \l RadioDelegate is similar to RadioButton, except that it is typically
42 used in views.
43
44 \code
45 ColumnLayout {
46 RadioButton {
47 checked: true
48 text: qsTr("First")
49 }
50 RadioButton {
51 text: qsTr("Second")
52 }
53 RadioButton {
54 text: qsTr("Third")
55 }
56 }
57 \endcode
58
59 \sa ButtonGroup, {Customizing RadioButton}, {Button Controls}, RadioDelegate
60*/
61
62class Q_QUICKTEMPLATES2_EXPORT QQuickRadioButtonPrivate : public QQuickAbstractButtonPrivate
63{
64 Q_DECLARE_PUBLIC(QQuickRadioButton)
65
66public:
67 QPalette defaultPalette() const override { return QQuickTheme::palette(QQuickTheme::RadioButton); }
68};
69
70QQuickRadioButton::QQuickRadioButton(QQuickItem *parent)
71 : QQuickAbstractButton(*(new QQuickRadioButtonPrivate), parent)
72{
73 setCheckable(true);
74 setAutoExclusive(true);
75}
76
77QFont QQuickRadioButton::defaultFont() const
78{
79 return QQuickTheme::font(QQuickTheme::RadioButton);
80}
81
82#if QT_CONFIG(accessibility)
83QAccessible::Role QQuickRadioButton::accessibleRole() const
84{
85 return QAccessible::RadioButton;
86}
87#endif
88
89QT_END_NAMESPACE
90
91#include "moc_qquickradiobutton_p.cpp"
Exclusive radio button that can be toggled on or off.