Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qabstractbutton.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 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 "private/qabstractbutton_p.h"
5
6#if QT_CONFIG(itemviews)
7#include "qabstractitemview.h"
8#endif
9#if QT_CONFIG(buttongroup)
10#include "qbuttongroup.h"
11#include "private/qbuttongroup_p.h"
12#endif
13#include "private/qapplication_p.h"
14#include "qabstractbutton_p.h"
15#include "qevent.h"
16#include "qpainter.h"
17#include "qapplication.h"
18#include "qstyle.h"
19#if QT_CONFIG(accessibility)
20#include "qaccessible.h"
21#endif
22#include <qpa/qplatformtheme.h>
23
24#include <QtCore/qpointer.h>
25
26#include <algorithm>
27
29
30#define AUTO_REPEAT_DELAY 300
31#define AUTO_REPEAT_INTERVAL 100
32
33Q_WIDGETS_EXPORT extern bool qt_tab_all_widgets();
34
139 :
140#ifndef QT_NO_SHORTCUT
141 shortcutId(0),
142#endif
143 checkable(false), checked(false), autoRepeat(false), autoExclusive(false),
144 down(false), blockRefresh(false), pressed(false),
145#if QT_CONFIG(buttongroup)
146 group(nullptr),
147#endif
148 autoRepeatDelay(AUTO_REPEAT_DELAY),
149 autoRepeatInterval(AUTO_REPEAT_INTERVAL),
150 controlType(type)
151{}
152
153QList<QAbstractButton *>QAbstractButtonPrivate::queryButtonList() const
154{
155#if QT_CONFIG(buttongroup)
156 if (group)
157 return group->d_func()->buttonList;
158#endif
159
160 if (!parent)
161 return {};
162 QList<QAbstractButton *> candidates = parent->findChildren<QAbstractButton *>();
163 if (autoExclusive) {
164 auto isNoMemberOfMyAutoExclusiveGroup = [](QAbstractButton *candidate) {
165 return !candidate->autoExclusive()
166#if QT_CONFIG(buttongroup)
167 || candidate->group()
168#endif
169 ;
170 };
171 candidates.removeIf(isNoMemberOfMyAutoExclusiveGroup);
172 }
173 return candidates;
174}
175
177{
178#if QT_CONFIG(buttongroup)
179 if (group)
180 return group->d_func()->checkedButton;
181#endif
182
183 Q_Q(const QAbstractButton);
184 QList<QAbstractButton *> buttonList = queryButtonList();
185 if (!autoExclusive || buttonList.size() == 1) // no group
186 return nullptr;
187
188 for (int i = 0; i < buttonList.size(); ++i) {
189 QAbstractButton *b = buttonList.at(i);
190 if (b->d_func()->checked && b != q)
191 return b;
192 }
193 return checked ? const_cast<QAbstractButton *>(q) : nullptr;
194}
195
197{
198#if QT_CONFIG(buttongroup)
199 Q_Q(QAbstractButton);
200 if (group) {
201 QAbstractButton *previous = group->d_func()->checkedButton;
202 group->d_func()->checkedButton = q;
203 if (group->d_func()->exclusive && previous && previous != q)
204 previous->nextCheckState();
205 } else
206#endif
207 if (autoExclusive) {
209 b->setChecked(false);
210 }
211}
212
214{
215 QList<QAbstractButton *> buttonList = queryButtonList();
216#if QT_CONFIG(buttongroup)
217 bool exclusive = group ? group->d_func()->exclusive : autoExclusive;
218#else
219 bool exclusive = autoExclusive;
220#endif
222 QAbstractButton *fb = qobject_cast<QAbstractButton *>(f);
223 if (!fb || !buttonList.contains(fb))
224 return;
225
226 QAbstractButton *candidate = nullptr;
227 int bestScore = -1;
228 QRect target = f->rect().translated(f->mapToGlobal(QPoint(0,0)));
229 QPoint goal = target.center();
231
232 for (int i = 0; i < buttonList.size(); ++i) {
233 QAbstractButton *button = buttonList.at(i);
234 if (button != f && button->window() == f->window() && button->isEnabled() && !button->isHidden() &&
235 (exclusive || (button->focusPolicy() & focus_flag) == focus_flag)) {
236 QRect buttonRect = button->rect().translated(button->mapToGlobal(QPoint(0,0)));
237 QPoint p = buttonRect.center();
238
239 //Priority to widgets that overlap on the same coordinate.
240 //In that case, the distance in the direction will be used as significant score,
241 //take also in account orthogonal distance in case two widget are in the same distance.
242 int score;
243 if ((buttonRect.x() < target.right() && target.x() < buttonRect.right())
244 && (key == Qt::Key_Up || key == Qt::Key_Down)) {
245 //one item's is at the vertical of the other
246 score = (qAbs(p.y() - goal.y()) << 16) + qAbs(p.x() - goal.x());
247 } else if ((buttonRect.y() < target.bottom() && target.y() < buttonRect.bottom())
248 && (key == Qt::Key_Left || key == Qt::Key_Right) ) {
249 //one item's is at the horizontal of the other
250 score = (qAbs(p.x() - goal.x()) << 16) + qAbs(p.y() - goal.y());
251 } else {
252 score = (1 << 30) + (p.y() - goal.y()) * (p.y() - goal.y()) + (p.x() - goal.x()) * (p.x() - goal.x());
253 }
254
255 if (score > bestScore && candidate)
256 continue;
257
258 switch(key) {
259 case Qt::Key_Up:
260 if (p.y() < goal.y()) {
261 candidate = button;
262 bestScore = score;
263 }
264 break;
265 case Qt::Key_Down:
266 if (p.y() > goal.y()) {
267 candidate = button;
268 bestScore = score;
269 }
270 break;
271 case Qt::Key_Left:
272 if (p.x() < goal.x()) {
273 candidate = button;
274 bestScore = score;
275 }
276 break;
277 case Qt::Key_Right:
278 if (p.x() > goal.x()) {
279 candidate = button;
280 bestScore = score;
281 }
282 break;
283 }
284 }
285 }
286
287 if (exclusive
288#ifdef QT_KEYPAD_NAVIGATION
289 && !QApplicationPrivate::keypadNavigationEnabled()
290#endif
291 && candidate
292 && fb->d_func()->checked
293 && candidate->d_func()->checkable)
294 candidate->click();
295
296 if (candidate) {
297 if (key == Qt::Key_Up || key == Qt::Key_Left)
299 else
300 candidate->setFocus(Qt::TabFocusReason);
301 }
302}
303
305{
306 Q_Q(QAbstractButton);
307#if QT_CONFIG(buttongroup)
308 if (!group && !autoExclusive)
309#else
310 if (!autoExclusive)
311#endif
312 return;
313
314 QList<QAbstractButton *> buttonList = queryButtonList();
315 for (int i = 0; i < buttonList.size(); ++i) {
316 QAbstractButton *b = buttonList.at(i);
317 if (!b->isCheckable())
318 continue;
319 b->setFocusPolicy((Qt::FocusPolicy) ((b == q || !q->isCheckable())
320 ? (b->focusPolicy() | Qt::TabFocus)
321 : (b->focusPolicy() & ~Qt::TabFocus)));
322 }
323}
324
326{
327 Q_Q(QAbstractButton);
328
329 q->setFocusPolicy(Qt::FocusPolicy(q->style()->styleHint(QStyle::SH_Button_FocusPolicy)));
331 q->setAttribute(Qt::WA_WState_OwnSizePolicy, false);
332 q->setForegroundRole(QPalette::ButtonText);
333 q->setBackgroundRole(QPalette::Button);
334}
335
337{
338 Q_Q(QAbstractButton);
339
340 if (blockRefresh)
341 return;
342 q->update();
343}
344
346{
347 Q_Q(QAbstractButton);
348
349 down = false;
350 blockRefresh = true;
351 bool changeState = true;
352 if (checked && queryCheckedButton() == q) {
353 // the checked button of an exclusive or autoexclusive group cannot be unchecked
354#if QT_CONFIG(buttongroup)
355 if (group ? group->d_func()->exclusive : autoExclusive)
356#else
357 if (autoExclusive)
358#endif
359 changeState = false;
360 }
361
362 QPointer<QAbstractButton> guard(q);
363 if (changeState) {
364 q->nextCheckState();
365 if (!guard)
366 return;
367 }
368 blockRefresh = false;
369 refresh();
370 q->repaint();
371 if (guard)
372 emitReleased();
373 if (guard)
374 emitClicked();
375}
376
378{
379 Q_Q(QAbstractButton);
380 QPointer<QAbstractButton> guard(q);
381 emit q->clicked(checked);
382#if QT_CONFIG(buttongroup)
383 if (guard && group) {
384 emit group->idClicked(group->id(q));
385 if (guard && group)
386 emit group->buttonClicked(q);
387 }
388#endif
389}
390
392{
393 Q_Q(QAbstractButton);
394 QPointer<QAbstractButton> guard(q);
395 emit q->pressed();
396#if QT_CONFIG(buttongroup)
397 if (guard && group) {
398 emit group->idPressed(group->id(q));
399 if (guard && group)
400 emit group->buttonPressed(q);
401 }
402#endif
403}
404
406{
407 Q_Q(QAbstractButton);
408 QPointer<QAbstractButton> guard(q);
409 emit q->released();
410#if QT_CONFIG(buttongroup)
411 if (guard && group) {
412 emit group->idReleased(group->id(q));
413 if (guard && group)
414 emit group->buttonReleased(q);
415 }
416#endif
417}
418
420{
421 Q_Q(QAbstractButton);
422 QPointer<QAbstractButton> guard(q);
423 emit q->toggled(checked);
424#if QT_CONFIG(buttongroup)
425 if (guard && group) {
426 emit group->idToggled(group->id(q), checked);
427 if (guard && group)
428 emit group->buttonToggled(q, checked);
429 }
430#endif
431}
432
437 : QWidget(*new QAbstractButtonPrivate, parent, { })
438{
439 Q_D(QAbstractButton);
440 d->init();
441}
442
447{
448#if QT_CONFIG(buttongroup)
449 Q_D(QAbstractButton);
450 if (d->group)
451 d->group->removeButton(this);
452#endif
453}
454
455
459 : QWidget(dd, parent, { })
460{
461 Q_D(QAbstractButton);
462 d->init();
463}
464
483{
484 Q_D(QAbstractButton);
485 if (d->text == text)
486 return;
487 d->text = text;
488#ifndef QT_NO_SHORTCUT
490 setShortcut(newMnemonic);
491#endif
492 d->sizeHint = QSize();
493 update();
495#if QT_CONFIG(accessibility)
496 QAccessibleEvent event(this, QAccessible::NameChanged);
497 QAccessible::updateAccessibility(&event);
498#endif
499}
500
502{
503 Q_D(const QAbstractButton);
504 return d->text;
505}
506
507
516{
517 Q_D(QAbstractButton);
518 d->icon = icon;
519 d->sizeHint = QSize();
520 update();
522}
523
525{
526 Q_D(const QAbstractButton);
527 return d->icon;
528}
529
530#ifndef QT_NO_SHORTCUT
537{
538 Q_D(QAbstractButton);
539 if (d->shortcutId != 0)
540 releaseShortcut(d->shortcutId);
541 d->shortcut = key;
542 d->shortcutId = grabShortcut(key);
543}
544
546{
547 Q_D(const QAbstractButton);
548 return d->shortcut;
549}
550#endif // QT_NO_SHORTCUT
551
561{
562 Q_D(QAbstractButton);
563 if (d->checkable == checkable)
564 return;
565
566 d->checkable = checkable;
567 d->checked = false;
568}
569
571{
572 Q_D(const QAbstractButton);
573 return d->checkable;
574}
575
585{
586 Q_D(QAbstractButton);
587 if (!d->checkable || d->checked == checked) {
588 if (!d->blockRefresh)
590 return;
591 }
592
593 if (!checked && d->queryCheckedButton() == this) {
594 // the checked button of an exclusive or autoexclusive group cannot be unchecked
595#if QT_CONFIG(buttongroup)
596 if (d->group ? d->group->d_func()->exclusive : d->autoExclusive)
597 return;
598 if (d->group)
599 d->group->d_func()->detectCheckedButton();
600#else
601 if (d->autoExclusive)
602 return;
603#endif
604 }
605
606 QPointer<QAbstractButton> guard(this);
607
608 d->checked = checked;
609 if (!d->blockRefresh)
611 d->refresh();
612
613 if (guard && checked)
614 d->notifyChecked();
615 if (guard)
616 d->emitToggled(checked);
617
618#if QT_CONFIG(accessibility)
619 if (guard) {
621 s.checked = true;
622 QAccessibleStateChangeEvent event(this, s);
623 QAccessible::updateAccessibility(&event);
624 }
625#endif
626}
627
629{
630 Q_D(const QAbstractButton);
631 return d->checked;
632}
633
644{
645 Q_D(QAbstractButton);
646 if (d->down == down)
647 return;
648 d->down = down;
649 d->refresh();
650 if (d->autoRepeat && d->down)
651 d->repeatTimer.start(d->autoRepeatDelay, this);
652 else
653 d->repeatTimer.stop();
654}
655
657{
658 Q_D(const QAbstractButton);
659 return d->down;
660}
661
677{
678 Q_D(QAbstractButton);
679 if (d->autoRepeat == autoRepeat)
680 return;
681 d->autoRepeat = autoRepeat;
682 if (d->autoRepeat && d->down)
683 d->repeatTimer.start(d->autoRepeatDelay, this);
684 else
685 d->repeatTimer.stop();
686}
687
689{
690 Q_D(const QAbstractButton);
691 return d->autoRepeat;
692}
693
705void QAbstractButton::setAutoRepeatDelay(int autoRepeatDelay)
706{
707 Q_D(QAbstractButton);
708 d->autoRepeatDelay = autoRepeatDelay;
709}
710
712{
713 Q_D(const QAbstractButton);
714 return d->autoRepeatDelay;
715}
716
728void QAbstractButton::setAutoRepeatInterval(int autoRepeatInterval)
729{
730 Q_D(QAbstractButton);
731 d->autoRepeatInterval = autoRepeatInterval;
732}
733
735{
736 Q_D(const QAbstractButton);
737 return d->autoRepeatInterval;
738}
739
740
741
759void QAbstractButton::setAutoExclusive(bool autoExclusive)
760{
761 Q_D(QAbstractButton);
762 d->autoExclusive = autoExclusive;
763}
764
766{
767 Q_D(const QAbstractButton);
768 return d->autoExclusive;
769}
770
771#if QT_CONFIG(buttongroup)
780QButtonGroup *QAbstractButton::group() const
781{
782 Q_D(const QAbstractButton);
783 return d->group;
784}
785#endif // QT_CONFIG(buttongroup)
786
801{
802 if (!isEnabled())
803 return;
804 Q_D(QAbstractButton);
805 if (d->checkable && focusPolicy() & Qt::ClickFocus)
806 setFocus();
807 setDown(true);
808 repaint();
809 if (!d->animateTimer.isActive())
810 d->emitPressed();
811 d->animateTimer.start(100, this);
812}
813
826{
827 if (!isEnabled())
828 return;
829 Q_D(QAbstractButton);
830 QPointer<QAbstractButton> guard(this);
831 d->down = true;
832 d->emitPressed();
833 if (guard) {
834 d->down = false;
836 if (guard)
837 d->emitReleased();
838 if (guard)
839 d->emitClicked();
840 }
841}
842
850{
851 Q_D(QAbstractButton);
852 setChecked(!d->checked);
853}
854
855
865
878
888{
889 return rect().contains(pos);
890}
891
894{
895 // as opposed to other widgets, disabled buttons accept mouse
896 // events. This avoids surprising click-through scenarios
897 if (!isEnabled()) {
898 switch(e->type()) {
910 return true;
911 default:
912 break;
913 }
914 }
915
916#ifndef QT_NO_SHORTCUT
917 if (e->type() == QEvent::Shortcut) {
918 Q_D(QAbstractButton);
919 QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
920 if (d->shortcutId != se->shortcutId())
921 return false;
922 if (!se->isAmbiguous()) {
923 if (!d->animateTimer.isActive())
924 animateClick();
925 } else {
926 if (focusPolicy() != Qt::NoFocus)
929 }
930 return true;
931 }
932#endif
933 return QWidget::event(e);
934}
935
938{
939 Q_D(QAbstractButton);
940 if (e->button() != Qt::LeftButton) {
941 e->ignore();
942 return;
943 }
944 if (hitButton(e->position().toPoint())) {
945 setDown(true);
946 d->pressed = true;
947 repaint();
948 d->emitPressed();
949 e->accept();
950 } else {
951 e->ignore();
952 }
953}
954
957{
958 Q_D(QAbstractButton);
959
960 if (e->button() != Qt::LeftButton) {
961 e->ignore();
962 return;
963 }
964
965 d->pressed = false;
966
967 if (!d->down) {
968 // refresh is required by QMacStyle to resume the default button animation
969 d->refresh();
970 e->ignore();
971 return;
972 }
973
974 if (hitButton(e->position().toPoint())) {
975 d->repeatTimer.stop();
976 d->click();
977 e->accept();
978 } else {
979 setDown(false);
980 e->ignore();
981 }
982}
983
986{
987 Q_D(QAbstractButton);
988 if (!(e->buttons() & Qt::LeftButton) || !d->pressed) {
989 e->ignore();
990 return;
991 }
992
993 if (hitButton(e->position().toPoint()) != d->down) {
994 setDown(!d->down);
995 repaint();
996 if (d->down)
997 d->emitPressed();
998 else
999 d->emitReleased();
1000 e->accept();
1001 } else if (!hitButton(e->position().toPoint())) {
1002 e->ignore();
1003 }
1004}
1005
1008{
1009 Q_D(QAbstractButton);
1010 bool next = true;
1011
1012 const auto key = e->key();
1013 const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()
1015 .value<QList<Qt::Key>>();
1016 if (buttonPressKeys.contains(key) && !e->isAutoRepeat()) {
1017 setDown(true);
1018 repaint();
1019 d->emitPressed();
1020 return;
1021 }
1022
1023 switch (key) {
1024 case Qt::Key_Up:
1025 next = false;
1026 Q_FALLTHROUGH();
1027 case Qt::Key_Left:
1028 case Qt::Key_Right:
1029 case Qt::Key_Down: {
1030#ifdef QT_KEYPAD_NAVIGATION
1031 if ((QApplicationPrivate::keypadNavigationEnabled()
1032 && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right))
1033 || (!QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional
1034 || (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down))) {
1035 e->ignore();
1036 return;
1037 }
1038#endif
1039 QWidget *pw = parentWidget();
1040 if (d->autoExclusive
1041#if QT_CONFIG(buttongroup)
1042 || d->group
1043#endif
1044#if QT_CONFIG(itemviews)
1045 || (pw && qobject_cast<QAbstractItemView *>(pw->parentWidget()))
1046#endif
1047 ) {
1048 // ### Using qobject_cast to check if the parent is a viewport of
1049 // QAbstractItemView is a crude hack, and should be revisited and
1050 // cleaned up when fixing task 194373. It's here to ensure that we
1051 // keep compatibility outside QAbstractItemView.
1052 d->moveFocus(e->key());
1053 if (hasFocus()) // nothing happened, propagate
1054 e->ignore();
1055 } else {
1056 // Prefer parent widget, use this if parent is absent
1057 QWidget *w = pw ? pw : this;
1058 bool reverse = (w->layoutDirection() == Qt::RightToLeft);
1059 if ((e->key() == Qt::Key_Left && !reverse)
1060 || (e->key() == Qt::Key_Right && reverse)) {
1061 next = false;
1062 }
1064 }
1065 break;
1066 }
1067 default:
1068#ifndef QT_NO_SHORTCUT
1069 if (e->matches(QKeySequence::Cancel) && d->down) {
1070 setDown(false);
1071 repaint();
1072 d->emitReleased();
1073 return;
1074 }
1075#endif
1076 e->ignore();
1077 }
1078}
1079
1082{
1083 Q_D(QAbstractButton);
1084
1085 if (!e->isAutoRepeat())
1086 d->repeatTimer.stop();
1087
1088 const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()
1090 .value<QList<Qt::Key>>();
1091 if (buttonPressKeys.contains(e->key()) && !e->isAutoRepeat() && d->down) {
1092 d->click();
1093 return;
1094 }
1095
1096 e->ignore();
1097}
1098
1102{
1103 Q_D(QAbstractButton);
1104 if (e->timerId() == d->repeatTimer.timerId()) {
1105 d->repeatTimer.start(d->autoRepeatInterval, this);
1106 if (d->down) {
1107 QPointer<QAbstractButton> guard(this);
1109 if (guard)
1110 d->emitReleased();
1111 if (guard)
1112 d->emitClicked();
1113 if (guard)
1114 d->emitPressed();
1115 }
1116 } else if (e->timerId() == d->animateTimer.timerId()) {
1117 d->animateTimer.stop();
1118 d->click();
1119 }
1120}
1121
1124{
1125 Q_D(QAbstractButton);
1126#ifdef QT_KEYPAD_NAVIGATION
1127 if (!QApplicationPrivate::keypadNavigationEnabled())
1128#endif
1129 d->fixFocusPolicy();
1131}
1132
1135{
1136 Q_D(QAbstractButton);
1137 if (e->reason() != Qt::PopupFocusReason && d->down) {
1138 d->down = false;
1139 d->emitReleased();
1140 }
1142}
1143
1146{
1147 Q_D(QAbstractButton);
1148 switch (e->type()) {
1150 if (!isEnabled() && d->down) {
1151 d->down = false;
1152 d->emitReleased();
1153 }
1154 break;
1155 default:
1156 d->sizeHint = QSize();
1157 break;
1158 }
1160}
1161
1235{
1236 Q_D(const QAbstractButton);
1237 if (d->iconSize.isValid())
1238 return d->iconSize;
1239 int e = style()->pixelMetric(QStyle::PM_ButtonIconSize, nullptr, this);
1240 return QSize(e, e);
1241}
1242
1244{
1245 Q_D(QAbstractButton);
1246 if (d->iconSize == size)
1247 return;
1248
1249 d->iconSize = size;
1250 d->sizeHint = QSize();
1252 if (isVisible()) {
1253 update();
1254 }
1255}
1256
1257
1258
1260
1261#include "moc_qabstractbutton.cpp"
QList< QAbstractButton * > queryButtonList() const
QSizePolicy::ControlType controlType
QAbstractButton * queryCheckedButton() const
void emitToggled(bool checked)
QAbstractButtonPrivate(QSizePolicy::ControlType type=QSizePolicy::DefaultType)
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
bool down
whether the button is pressed down
void mouseMoveEvent(QMouseEvent *e) override
\reimp
void animateClick()
Performs an animated click: the button is pressed immediately, and released 100ms later.
int autoRepeatDelay
the initial delay of auto-repetition
QIcon icon
the icon shown on the button
void click()
Performs a click.
void mousePressEvent(QMouseEvent *e) override
\reimp
void setAutoRepeatDelay(int)
void mouseReleaseEvent(QMouseEvent *e) override
\reimp
void setAutoExclusive(bool)
bool checkable
whether the button is checkable
void focusInEvent(QFocusEvent *e) override
\reimp
bool isCheckable() const
void setShortcut(const QKeySequence &key)
void setIcon(const QIcon &icon)
bool event(QEvent *e) override
\reimp
bool autoRepeat
whether autoRepeat is enabled
void setAutoRepeatInterval(int)
int autoRepeatInterval
the interval of auto-repetition
bool checked
whether the button is checked
void toggle()
Toggles the state of a checkable button.
QKeySequence shortcut
the mnemonic associated with the button
void timerEvent(QTimerEvent *e) override
\reimp
~QAbstractButton()
Destroys the button.
bool autoExclusive
whether auto-exclusivity is enabled
QAbstractButton(QWidget *parent=nullptr)
Constructs an abstract button with a parent.
void setIconSize(const QSize &size)
void keyPressEvent(QKeyEvent *e) override
\reimp
void changeEvent(QEvent *e) override
\reimp
virtual void checkStateSet()
This virtual handler is called when setChecked() is used, unless it is called from within nextCheckSt...
void setText(const QString &text)
void keyReleaseEvent(QKeyEvent *e) override
\reimp
bool isChecked() const
QSize iconSize
the icon size used for this button.
void focusOutEvent(QFocusEvent *e) override
\reimp
virtual bool hitButton(const QPoint &pos) const
Returns true if pos is inside the clickable button rectangle; otherwise returns false.
virtual void nextCheckState()
This virtual handler is called when a button is clicked.
QString text
the text shown on the button
\inmodule QtGui
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
The QButtonGroup class provides a container to organize groups of button widgets.
\inmodule QtCore
Definition qcoreevent.h:45
@ TabletMove
Definition qcoreevent.h:121
@ EnabledChange
Definition qcoreevent.h:134
@ MouseMove
Definition qcoreevent.h:63
@ MouseButtonPress
Definition qcoreevent.h:60
@ HoverLeave
Definition qcoreevent.h:176
@ HoverEnter
Definition qcoreevent.h:175
@ TabletRelease
Definition qcoreevent.h:127
@ HoverMove
Definition qcoreevent.h:177
@ TabletPress
Definition qcoreevent.h:126
@ MouseButtonDblClick
Definition qcoreevent.h:62
@ ContextMenu
Definition qcoreevent.h:119
@ MouseButtonRelease
Definition qcoreevent.h:61
Type type() const
Returns the event type.
Definition qcoreevent.h:304
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:311
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:310
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
Qt::FocusReason reason() const
Returns the reason for this focus event.
Definition qevent.cpp:1569
static QPlatformTheme * platformTheme()
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
The QKeyEvent class describes a key event.
Definition qevent.h:424
bool isAutoRepeat() const
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initia...
Definition qevent.h:444
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:434
The QKeySequence class encapsulates a key sequence as used by shortcuts.
static QKeySequence mnemonic(const QString &text)
Returns the shortcut key sequence for the mnemonic in text, or an empty key sequence if no mnemonics ...
\inmodule QtGui
Definition qevent.h:196
QObject * parent
Definition qobject.h:73
QList< T > findChildren(QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
Returns all children of this object with the given name that can be cast to type T,...
Definition qobject.h:164
@ ButtonText
Definition qpalette.h:52
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:855
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:261
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
constexpr QPoint center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:233
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:119
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:116
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition qevent.h:117
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
@ SH_Button_FocusPolicy
Definition qstyle.h:634
@ PM_ButtonIconSize
Definition qstyle.h:507
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
\inmodule QtCore
Definition qcoreevent.h:366
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition qcoreevent.h:370
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
void repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the ...
QWidget * window() const
Returns the window for this widget, i.e.
Definition qwidget.cpp:4313
void releaseShortcut(int id)
Removes the shortcut with the given id from Qt's shortcut system.
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition qwidget.h:877
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
QPointF mapToGlobal(const QPointF &) const
Translates the widget coordinate pos to global screen coordinates.
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
virtual void focusInEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition qwidget.cpp:9665
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab,...
Definition qwidget.cpp:6777
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
void setFocus()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:423
bool isEnabled() const
Definition qwidget.h:814
void update()
Updates the widget unless updates are disabled or the widget is hidden.
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9382
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
int grabShortcut(const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context.
QStyle * style() const
Definition qwidget.cpp:2600
bool hasFocus() const
Definition qwidget.cpp:6446
virtual void focusOutEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition qwidget.cpp:9691
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
Definition qwidget.h:140
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
bool isVisible() const
Definition qwidget.h:874
QString text
QPushButton * button
[2]
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ NavigationModeKeypadDirectional
@ LeftButton
Definition qnamespace.h:58
@ WA_KeyboardFocusChange
Definition qnamespace.h:344
@ WA_WState_OwnSizePolicy
Definition qnamespace.h:334
@ RightToLeft
FocusPolicy
Definition qnamespace.h:106
@ ClickFocus
Definition qnamespace.h:109
@ NoFocus
Definition qnamespace.h:107
@ TabFocus
Definition qnamespace.h:108
@ StrongFocus
Definition qnamespace.h:110
@ Key_Right
Definition qnamespace.h:679
@ Key_Left
Definition qnamespace.h:677
@ Key_Up
Definition qnamespace.h:678
@ Key_Down
Definition qnamespace.h:680
@ PopupFocusReason
@ BacktabFocusReason
@ TabFocusReason
@ ShortcutFocusReason
#define AUTO_REPEAT_DELAY
Q_WIDGETS_EXPORT bool qt_tab_all_widgets()
#define AUTO_REPEAT_INTERVAL
#define Q_FALLTHROUGH()
Q_WIDGETS_EXPORT bool qt_tab_all_widgets()
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
GLboolean GLboolean GLboolean b
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLfloat GLfloat f
GLenum type
GLboolean GLuint group
GLenum target
struct _cl_event * event
GLdouble s
[6]
Definition qopenglext.h:235
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
#define QT_CONFIG(feature)
#define emit
unsigned int uint
Definition qtypes.h:34
if(qFloatDistance(a, b)<(1<< 7))
[0]
QObject::connect nullptr