Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qquickcheckbox.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
4#include "qquickcheckbox_p.h"
6
7#include <QtGui/qpa/qplatformtheme.h>
8#include <QtQml/qjsvalue.h>
9
11
16
68{
69 Q_DECLARE_PUBLIC(QQuickCheckBox)
70
71public:
72 void setNextCheckState(const QJSValue &callback);
73
75
76 bool tristate = false;
79};
80
82{
83 Q_Q(QQuickCheckBox);
84 nextCheckState = callback;
85 emit q->nextCheckStateChanged();
86}
87
88QQuickCheckBox::QQuickCheckBox(QQuickItem *parent)
90{
91 setCheckable(true);
92}
93
105bool QQuickCheckBox::isTristate() const
106{
107 Q_D(const QQuickCheckBox);
108 return d->tristate;
109}
110
111void QQuickCheckBox::setTristate(bool tristate)
112{
113 Q_D(QQuickCheckBox);
114 if (d->tristate == tristate)
115 return;
116
117 d->tristate = tristate;
119}
120
134{
135 Q_D(const QQuickCheckBox);
136 return d->checkState;
137}
138
139void QQuickCheckBox::setCheckState(Qt::CheckState state)
140{
141 Q_D(QQuickCheckBox);
142 if (d->checkState == state)
143 return;
144
145 bool wasChecked = isChecked();
146 d->checked = state == Qt::Checked;
147 d->checkState = state;
149 if (d->checked != wasChecked)
151}
152
154{
156}
157
159{
160 if (change == ButtonCheckedChange)
161 setCheckState(isChecked() ? Qt::Checked : Qt::Unchecked);
162 else
164}
165
200{
201 Q_D(QQuickCheckBox);
202 if (d->nextCheckState.isCallable())
203 setCheckState(static_cast<Qt::CheckState>(d->nextCheckState.call().toInt()));
204 else if (d->tristate)
205 setCheckState(static_cast<Qt::CheckState>((d->checkState + 1) % 3));
206 else
208}
209
211
212#include "moc_qquickcheckbox_p.cpp"
\reentrant
Definition qfont.h:20
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
bool isChecked() const
\qmlproperty bool QtQuick.Controls::AbstractButton::checked
virtual void buttonChange(ButtonChange change)
Check button that can be toggled on or off.
void setNextCheckState(const QJSValue &callback)
Qt::CheckState checkState
QPalette defaultPalette() const override
QFont defaultFont() const override
void buttonChange(ButtonChange change) override
void checkStateChanged()
void nextCheckState() override
void tristateChanged()
Qt::CheckState checkState
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
QString state() const
\qmlproperty string QtQuick::Item::state
static QPalette palette(Scope scope)
static QFont font(Scope scope)
else opt state
[0]
Combined button and popup list for selecting options.
CheckState
@ Unchecked
@ Checked
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define emit
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent