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
qtoolbutton.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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 "qtoolbutton.h"
5
6#include <qapplication.h>
7#include <qdrawutil.h>
8#include <qevent.h>
9#include <qicon.h>
10#include <qpainter.h>
11#include <qpointer.h>
12#include <qstyle.h>
13#include <qstyleoption.h>
14#if QT_CONFIG(tooltip)
15#include <qtooltip.h>
16#endif
17#if QT_CONFIG(mainwindow)
18#include <qmainwindow.h>
19#endif
20#if QT_CONFIG(toolbar)
21#include <qtoolbar.h>
22#endif
23#include <qvariant.h>
24#include <qstylepainter.h>
25#include <private/qabstractbutton_p.h>
26#include <private/qaction_p.h>
27#if QT_CONFIG(menu)
28#include <qmenu.h>
29#include <private/qmenu_p.h>
30#endif
31
33
34using namespace Qt::StringLiterals;
35
37{
38 Q_DECLARE_PUBLIC(QToolButton)
39public:
40 void init();
41#if QT_CONFIG(menu)
42 void onButtonPressed();
43 void onButtonReleased();
44 void popupTimerDone();
45 void updateButtonDown();
46 void onMenuTriggered(QAction *);
47#endif
48 bool updateHoverControl(const QPoint &pos);
49 void onActionTriggered();
53 QPointer<QAction> menuAction; //the menu set by the user (setMenu)
55 int delay;
65#if QT_CONFIG(menu)
66 bool hasMenu() const;
67 //workaround for task 177850
68 QList<QAction *> actionsCopy;
69#endif
70};
71
72#if QT_CONFIG(menu)
73bool QToolButtonPrivate::hasMenu() const
74{
75 return ((defaultAction && defaultAction->menu())
76 || (menuAction && menuAction->menu())
77 || actions.size() > (defaultAction ? 1 : 0));
78}
79#endif
80
157 : QAbstractButton(*new QToolButtonPrivate, parent)
158{
159 Q_D(QToolButton);
160 d->init();
161}
162
163
164
165/* Set-up code common to all the constructors */
166
168{
169 Q_Q(QToolButton);
170 defaultAction = nullptr;
171#if QT_CONFIG(toolbar)
172 if (qobject_cast<QToolBar*>(parent))
173 autoRaise = true;
174 else
175#endif
176 autoRaise = false;
178 menuButtonDown = false;
181
184
185 q->setFocusPolicy(Qt::TabFocus);
188
189#if QT_CONFIG(menu)
191 this, &QToolButtonPrivate::onButtonPressed);
193 this, &QToolButtonPrivate::onButtonReleased);
194#endif
195
197 delay = q->style()->styleHint(QStyle::SH_ToolButton_PopupDelay, nullptr, q);
198}
199
208{
209 if (!option)
210 return;
211
212 Q_D(const QToolButton);
213 option->initFrom(this);
214 option->iconSize = iconSize(); //default value
215
216#if QT_CONFIG(toolbar)
217 if (parentWidget()) {
218 if (QToolBar *toolBar = qobject_cast<QToolBar *>(parentWidget())) {
219 option->iconSize = toolBar->iconSize();
220 }
221 }
222#endif // QT_CONFIG(toolbar)
223
224 option->text = d->text;
225 option->icon = d->icon;
226 option->arrowType = d->arrowType;
227 if (d->down)
229 if (d->checked)
230 option->state |= QStyle::State_On;
231 if (d->autoRaise)
233 if (!d->checked && !d->down)
235
236 option->subControls = QStyle::SC_ToolButton;
237 option->activeSubControls = QStyle::SC_None;
238
240 if (d->popupMode == QToolButton::MenuButtonPopup) {
241 option->subControls |= QStyle::SC_ToolButtonMenu;
243 }
244 if (option->state & QStyle::State_MouseOver) {
245 option->activeSubControls = d->hoverControl;
246 }
247 if (d->menuButtonDown) {
249 option->activeSubControls |= QStyle::SC_ToolButtonMenu;
250 }
251 if (d->down) {
253 option->activeSubControls |= QStyle::SC_ToolButton;
254 }
255
256
257 if (d->arrowType != Qt::NoArrow)
259 if (d->popupMode == QToolButton::DelayedPopup)
261#if QT_CONFIG(menu)
262 if (d->hasMenu())
264#endif
265 if (d->toolButtonStyle == Qt::ToolButtonFollowStyle) {
266 option->toolButtonStyle = Qt::ToolButtonStyle(style()->styleHint(QStyle::SH_ToolButtonStyle, option, this));
267 } else
268 option->toolButtonStyle = d->toolButtonStyle;
269
270 if (option->toolButtonStyle == Qt::ToolButtonTextBesideIcon) {
271 // If the action is not prioritized, remove the text label to save space
272 if (d->defaultAction && d->defaultAction->priority() < QAction::NormalPriority)
273 option->toolButtonStyle = Qt::ToolButtonIconOnly;
274 }
275
276 if (d->icon.isNull() && d->arrowType == Qt::NoArrow) {
277 if (!d->text.isEmpty())
278 option->toolButtonStyle = Qt::ToolButtonTextOnly;
279 else if (option->toolButtonStyle != Qt::ToolButtonTextOnly)
280 option->toolButtonStyle = Qt::ToolButtonIconOnly;
281 }
282
283 option->pos = pos();
284 option->font = font();
285}
286
294
299{
300 Q_D(const QToolButton);
301 if (d->sizeHint.isValid())
302 return d->sizeHint;
304
305 int w = 0, h = 0;
308
310 if (opt.toolButtonStyle != Qt::ToolButtonTextOnly) {
312 w = icon.width();
313 h = icon.height();
314 }
315
316 if (opt.toolButtonStyle != Qt::ToolButtonIconOnly) {
317 QSize textSize = fm.size(Qt::TextShowMnemonic, text());
318 textSize.setWidth(textSize.width() + fm.horizontalAdvance(u' ') * 2);
319 if (opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
320 h += 4 + textSize.height();
321 if (textSize.width() > w)
322 w = textSize.width();
323 } else if (opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon) {
324 w += 4 + textSize.width();
325 if (textSize.height() > h)
326 h = textSize.height();
327 } else { // TextOnly
328 w = textSize.width();
329 h = textSize.height();
330 }
331 }
332
333 opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height
334 if (d->popupMode == MenuButtonPopup)
336
337 d->sizeHint = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this);
338 return d->sizeHint;
339}
340
345{
346 return sizeHint();
347}
348
374{
375 Q_D(const QToolButton);
376 return d->toolButtonStyle;
377}
378
380{
381 Q_D(const QToolButton);
382 return d->arrowType;
383}
384
385
387{
388 Q_D(QToolButton);
389 if (d->toolButtonStyle == style)
390 return;
391
392 d->toolButtonStyle = style;
393 d->sizeHint = QSize();
395 if (isVisible()) {
396 update();
397 }
398}
399
401{
402 Q_D(QToolButton);
403 if (d->arrowType == type)
404 return;
405
406 d->arrowType = type;
407 d->sizeHint = QSize();
409 if (isVisible()) {
410 update();
411 }
412}
413
426
431{
432 Q_D(QToolButton);
433 auto action = static_cast<QAction *>(event->action());
434 switch (event->type()) {
436 if (action == d->defaultAction)
437 setDefaultAction(action); // update button state
438 break;
442 break;
444 if (d->defaultAction == action)
445 d->defaultAction = nullptr;
446#if QT_CONFIG(menu)
447 if (action == d->menuAction)
448 d->menuAction = nullptr;
449#endif
450 action->disconnect(this);
451 break;
452 default:
453 ;
454 }
456}
457
459{
460 Q_Q(QToolButton);
462 q->initStyleOption(&opt);
463 opt.subControls = QStyle::SC_All;
464 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ToolButton, &opt, pos, q);
466 hoverRect = QRect();
467 else
468 hoverRect = q->style()->subControlRect(QStyle::CC_ToolButton, &opt, hoverControl, q);
469 return hoverControl;
470}
471
473{
474 Q_Q(QToolButton);
475 QRect lastHoverRect = hoverRect;
476 QStyle::SubControl lastHoverControl = hoverControl;
477 bool doesHover = q->testAttribute(Qt::WA_Hover);
478 if (lastHoverControl != newHoverControl(pos) && doesHover) {
479 q->update(lastHoverRect);
480 q->update(hoverRect);
481 return true;
482 }
483 return !doesHover;
484}
485
487{
488 Q_Q(QToolButton);
489 if (QAction *action = qobject_cast<QAction *>(q->sender()))
490 emit q->triggered(action);
491}
492
497{
498 Q_D(QToolButton);
499 if (d->autoRaise)
500 update();
501 if (d->defaultAction)
502 d->defaultAction->hover();
504}
505
506
511{
512 Q_D(QToolButton);
513 if (d->autoRaise)
514 update();
515
517}
518
519
524{
525#if QT_CONFIG(menu)
526 Q_D(QToolButton);
527 if (e->timerId() == d->popupTimer.timerId()) {
528 d->popupTimerDone();
529 return;
530 }
531#endif
533}
534
535
540{
541#if QT_CONFIG(toolbar)
542 Q_D(QToolButton);
543 if (e->type() == QEvent::ParentChange) {
544 if (qobject_cast<QToolBar*>(parentWidget()))
545 d->autoRaise = true;
546 } else if (e->type() == QEvent::StyleChange
547#ifdef Q_OS_MAC
548 || e->type() == QEvent::MacSizeChange
549#endif
550 ) {
551 d->delay = style()->styleHint(QStyle::SH_ToolButton_PopupDelay, nullptr, this);
552 d->setLayoutItemMargins(QStyle::SE_ToolButtonLayoutItem);
553 }
554#endif
556}
557
562{
563 Q_D(QToolButton);
564#if QT_CONFIG(menu)
567 if (e->button() == Qt::LeftButton && (d->popupMode == MenuButtonPopup)) {
570 if (popupr.isValid() && popupr.contains(e->position().toPoint())) {
572 showMenu();
573 return;
574 }
575 }
576#endif
579}
580
585{
586 Q_D(QToolButton);
587 QPointer<QAbstractButton> guard(this);
589 if (guard)
590 d->buttonPressed = QToolButtonPrivate::NoButtonPressed;
591}
592
597{
598 Q_D(const QToolButton);
600 return (d->buttonPressed != QToolButtonPrivate::MenuButtonPressed);
601 return false;
602}
603
604
605#if QT_CONFIG(menu)
615void QToolButton::setMenu(QMenu* menu)
616{
617 Q_D(QToolButton);
618
619 if (d->menuAction == (menu ? menu->menuAction() : nullptr))
620 return;
621
622 if (d->menuAction)
623 removeAction(d->menuAction);
624
625 if (menu) {
626 d->menuAction = menu->menuAction();
627 addAction(d->menuAction);
628 } else {
629 d->menuAction = nullptr;
630 }
631
632 // changing the menu set may change the size hint, so reset it
633 d->sizeHint = QSize();
635 update();
636}
637
644QMenu* QToolButton::menu() const
645{
646 Q_D(const QToolButton);
647 if (d->menuAction)
648 return d->menuAction->menu();
649 return nullptr;
650}
651
657void QToolButton::showMenu()
658{
659 Q_D(QToolButton);
660 if (!d->hasMenu()) {
661 d->menuButtonDown = false;
662 return; // no menu to show
663 }
664 // prevent recursions spinning another event loop
665 if (d->menuButtonDown)
666 return;
667
668
669 d->menuButtonDown = true;
670 repaint();
671 d->popupTimer.stop();
672 d->popupTimerDone();
673}
674
675void QToolButtonPrivate::onButtonPressed()
676{
677 Q_Q(QToolButton);
678 if (!hasMenu())
679 return; // no menu to show
681 return;
682 else if (delay > 0 && popupMode == QToolButton::DelayedPopup)
684 else if (delay == 0 || popupMode == QToolButton::InstantPopup)
685 q->showMenu();
686}
687
688void QToolButtonPrivate::onButtonReleased()
689{
691}
692
693static QPoint positionMenu(const QToolButton *q, bool horizontal,
694 const QSize &sh)
695{
696 QPoint p;
697 const QRect rect = q->rect(); // Find screen via point in case of QGraphicsProxyWidget.
698 const QRect screen = QWidgetPrivate::availableScreenGeometry(q, q->mapToGlobal(rect.center()));
699 if (horizontal) {
700 if (q->isRightToLeft()) {
701 if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.bottom()) {
702 p = q->mapToGlobal(rect.bottomRight());
703 } else {
704 p = q->mapToGlobal(rect.topRight() - QPoint(0, sh.height()));
705 }
706 p.rx() -= sh.width();
707 } else {
708 if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.bottom()) {
709 p = q->mapToGlobal(rect.bottomLeft());
710 } else {
711 p = q->mapToGlobal(rect.topLeft() - QPoint(0, sh.height()));
712 }
713 }
714 } else {
715 if (q->isRightToLeft()) {
716 if (q->mapToGlobal(QPoint(rect.left(), 0)).x() - sh.width() <= screen.x()) {
717 p = q->mapToGlobal(rect.topRight());
718 } else {
719 p = q->mapToGlobal(rect.topLeft());
720 p.rx() -= sh.width();
721 }
722 } else {
723 if (q->mapToGlobal(QPoint(rect.right(), 0)).x() + sh.width() <= screen.right()) {
724 p = q->mapToGlobal(rect.topRight());
725 } else {
726 p = q->mapToGlobal(rect.topLeft() - QPoint(sh.width(), 0));
727 }
728 }
729 }
730
731 // QTBUG-118695 Force point inside the current screen. If the returned point
732 // is not found inside any screen, QMenu's positioning logic kicks in without
733 // taking the QToolButton's screen into account. This can cause the menu to
734 // end up on primary monitor, even if the QToolButton is on a non-primary monitor.
735 p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width()));
736 p.ry() = qMax(screen.top(), qMin(p.y() + 1, screen.bottom()));
737 return p;
738}
739
740void QToolButtonPrivate::popupTimerDone()
741{
742 Q_Q(QToolButton);
744 if (!menuButtonDown && !down)
745 return;
746
747 menuButtonDown = true;
748 QPointer<QMenu> actualMenu;
749 bool mustDeleteActualMenu = false;
750 if (menuAction) {
751 actualMenu = menuAction->menu();
752 } else if (defaultAction && defaultAction->menu()) {
753 actualMenu = defaultAction->menu();
754 } else {
755 actualMenu = new QMenu(q);
756 mustDeleteActualMenu = true;
757 for (int i = 0; i < actions.size(); i++)
758 actualMenu->addAction(actions.at(i));
759 }
760 repeat = q->autoRepeat();
761 q->setAutoRepeat(false);
762 bool horizontal = true;
763#if QT_CONFIG(toolbar)
764 QToolBar *tb = qobject_cast<QToolBar*>(parent);
765 if (tb && tb->orientation() == Qt::Vertical)
766 horizontal = false;
767#endif
768 QPointer<QToolButton> that = q;
769 actualMenu->setNoReplayFor(q);
770 if (!mustDeleteActualMenu) { //only if action are not in this widget
772 this, &QToolButtonPrivate::onMenuTriggered);
773 }
775 this, &QToolButtonPrivate::updateButtonDown);
776 actualMenu->d_func()->causedPopup.widget = q;
777 actualMenu->d_func()->causedPopup.action = defaultAction;
778 actionsCopy = q->actions(); //(the list of action may be modified in slots)
779
780 // QTBUG-78966, Delay positioning until after aboutToShow().
781 auto positionFunction = [q, horizontal](const QSize &sizeHint) {
782 return positionMenu(q, horizontal, sizeHint); };
783 const auto initialPos = positionFunction(actualMenu->sizeHint());
784 actualMenu->d_func()->exec(initialPos, nullptr, positionFunction);
785
786 if (!that)
787 return;
788
790 this, &QToolButtonPrivate::updateButtonDown);
791 if (mustDeleteActualMenu) {
792 delete actualMenu;
793 } else {
795 this, &QToolButtonPrivate::onMenuTriggered);
796 }
797
798 actionsCopy.clear();
799
800 if (repeat)
801 q->setAutoRepeat(true);
802}
803
804void QToolButtonPrivate::updateButtonDown()
805{
806 Q_Q(QToolButton);
807 menuButtonDown = false;
808 if (q->isDown())
809 q->setDown(false);
810 else
811 q->repaint();
812}
813
814void QToolButtonPrivate::onMenuTriggered(QAction *action)
815{
816 Q_Q(QToolButton);
817 if (action && !actionsCopy.contains(action))
818 emit q->triggered(action);
819}
820
851void QToolButton::setPopupMode(ToolButtonPopupMode mode)
852{
853 Q_D(QToolButton);
854 d->popupMode = mode;
855}
856
857QToolButton::ToolButtonPopupMode QToolButton::popupMode() const
858{
859 Q_D(const QToolButton);
860 return d->popupMode;
861}
862#endif
863
873{
874 Q_D(QToolButton);
875 d->autoRaise = enable;
876
877 update();
878}
879
881{
882 Q_D(const QToolButton);
883 return d->autoRaise;
884}
885
909{
910 Q_D(QToolButton);
911#if QT_CONFIG(menu)
912 bool hadMenu = false;
913 hadMenu = d->hasMenu();
914#endif
915 d->defaultAction = action;
916 if (!action)
917 return;
918 if (!actions().contains(action))
919 addAction(action);
920 QString buttonText = action->iconText();
921 // If iconText() is generated from text(), we need to escape any '&'s so they
922 // don't turn into shortcuts
923 if (QActionPrivate::get(action)->iconText.isEmpty())
924 buttonText.replace("&"_L1, "&&"_L1);
925 setText(buttonText);
926 setIcon(action->icon());
927#if QT_CONFIG(tooltip)
928 setToolTip(action->toolTip());
929#endif
930#if QT_CONFIG(statustip)
931 setStatusTip(action->statusTip());
932#endif
933#if QT_CONFIG(whatsthis)
934 setWhatsThis(action->whatsThis());
935#endif
936#if QT_CONFIG(menu)
937 if (action->menu() && !hadMenu) {
938 // new 'default' popup mode defined introduced by tool bar. We
939 // should have changed QToolButton's default instead. Do that
940 // in 4.2.
941 setPopupMode(QToolButton::MenuButtonPopup);
942 }
943#endif
944 setCheckable(action->isCheckable());
945 setChecked(action->isChecked());
946 setEnabled(action->isEnabled());
947 if (action->d_func()->fontSet)
948 setFont(action->font());
949}
950
951
958{
959 Q_D(const QToolButton);
960 return d->defaultAction;
961}
962
967{
968 Q_D(QToolButton);
969 if (d->defaultAction && d->defaultAction->isCheckable())
970 d->defaultAction->setChecked(isChecked());
971}
972
977{
978 Q_D(QToolButton);
979 if (!d->defaultAction)
981 else
982 d->defaultAction->trigger();
983}
984
987{
988 switch(event->type()) {
992 if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
993 d_func()->updateHoverControl(he->position().toPoint());
994 break;
995 default:
996 break;
997 }
999}
1000
1002
1003#include "moc_qtoolbutton.cpp"
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
QIcon icon
the icon shown on the button
void mousePressEvent(QMouseEvent *e) override
\reimp
void mouseReleaseEvent(QMouseEvent *e) override
\reimp
void setIcon(const QIcon &icon)
bool event(QEvent *e) override
\reimp
void released()
This signal is emitted when the button is released.
void pressed()
This signal is emitted when the button is pressed down.
void timerEvent(QTimerEvent *e) override
\reimp
void changeEvent(QEvent *e) override
\reimp
void setText(const QString &text)
bool isChecked() const
QSize iconSize
the icon size used for this button.
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
The QActionEvent class provides an event that is generated when a QAction is added,...
static QActionPrivate * get(QAction *q)
Definition qaction_p.h:47
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
QString iconText
the action's descriptive icon text
Definition qaction.h:40
T menu() const
Returns the menu contained by this action.
Definition qaction.h:186
@ NormalPriority
Definition qaction.h:65
QString statusTip
the action's status tip
Definition qaction.h:42
bool isCheckable() const
Definition qaction.cpp:847
QString whatsThis
the action's "What's This?" help text
Definition qaction.h:43
void triggered(bool checked=false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a m...
QFont font
the action's font
Definition qaction.h:44
QString toolTip
the action's tooltip
Definition qaction.h:41
bool isChecked() const
Definition qaction.cpp:892
QIcon icon
the action's icon
Definition qaction.h:38
bool isEnabled() const
Definition qaction.cpp:971
\inmodule QtCore
Definition qbasictimer.h:18
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
void stop()
Stops the timer.
\inmodule QtGui
Definition qevent.h:165
\inmodule QtCore
Definition qcoreevent.h:45
@ ActionRemoved
Definition qcoreevent.h:153
@ ParentChange
Definition qcoreevent.h:80
@ ActionAdded
Definition qcoreevent.h:152
@ StyleChange
Definition qcoreevent.h:136
@ ActionChanged
Definition qcoreevent.h:151
@ HoverLeave
Definition qcoreevent.h:176
@ HoverEnter
Definition qcoreevent.h:175
@ HoverMove
Definition qcoreevent.h:177
@ MacSizeChange
Definition qcoreevent.h:217
Type type() const
Returns the event type.
Definition qcoreevent.h:304
\reentrant \inmodule QtGui
\inmodule QtGui
Definition qevent.h:246
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
void triggered(QAction *action)
This signal is emitted when an action in this menu is triggered.
void aboutToHide()
QAction * menuAction() const
Returns the action associated with this menu.
Definition qmenu.cpp:1069
\inmodule QtGui
Definition qevent.h:196
QObject * parent
Definition qobject.h:73
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
static bool disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot)
Definition qobject_p.h:328
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
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
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
Definition qrect.h:387
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
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
Definition qsize.h:136
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString & replace(qsizetype i, qsizetype len, QChar after)
Definition qstring.cpp:3824
\variable QStyleOptionDockWidget::title
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
@ State_MouseOver
Definition qstyle.h:80
@ State_Sunken
Definition qstyle.h:69
@ State_AutoRaise
Definition qstyle.h:79
@ State_On
Definition qstyle.h:72
@ State_Raised
Definition qstyle.h:68
@ CT_ToolButton
Definition qstyle.h:550
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=nullptr) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=nullptr) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
@ SH_ToolButtonStyle
Definition qstyle.h:679
@ SH_ToolButton_PopupDelay
Definition qstyle.h:637
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
@ PM_MenuButtonIndicator
Definition qstyle.h:416
@ CC_ToolButton
Definition qstyle.h:336
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
@ SE_ToolButtonLayoutItem
Definition qstyle.h:298
SubControl
This enum describes the available sub controls.
Definition qstyle.h:347
@ SC_ToolButton
Definition qstyle.h:373
@ SC_All
Definition qstyle.h:400
@ SC_None
Definition qstyle.h:348
@ SC_ToolButtonMenu
Definition qstyle.h:374
\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 QToolBar class provides a movable panel that contains a set of controls.
Definition qtoolbar.h:23
QToolButton::ToolButtonPopupMode popupMode
QAction * defaultAction
bool updateHoverControl(const QPoint &pos)
QPointer< QAction > menuAction
Qt::ArrowType arrowType
QStyle::SubControl hoverControl
Qt::ToolButtonStyle toolButtonStyle
QStyle::SubControl newHoverControl(const QPoint &pos)
QBasicTimer popupTimer
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition qtoolbutton.h:20
bool autoRaise
whether auto-raising is enabled or not.
Definition qtoolbutton.h:27
~QToolButton()
Destroys the object and frees any allocated resources.
void actionEvent(QActionEvent *) override
\reimp
QSize minimumSizeHint() const override
\reimp
void checkStateSet() override
\reimp
QSize sizeHint() const override
\reimp
void setAutoRaise(bool enable)
QAction * defaultAction() const
Returns the default action.
void leaveEvent(QEvent *) override
\reimp
void setToolButtonStyle(Qt::ToolButtonStyle style)
Qt::ToolButtonStyle toolButtonStyle
whether the tool button displays an icon only, text only, or text beside/below the icon.
Definition qtoolbutton.h:26
void mousePressEvent(QMouseEvent *) override
\reimp
QToolButton(QWidget *parent=nullptr)
Constructs an empty tool button with parent parent.
Qt::ArrowType arrowType
whether the button displays an arrow instead of a normal icon
Definition qtoolbutton.h:28
bool event(QEvent *e) override
\reimp
void changeEvent(QEvent *) override
\reimp
void setDefaultAction(QAction *)
Sets the default action to action.
void nextCheckState() override
\reimp
void setArrowType(Qt::ArrowType type)
void enterEvent(QEnterEvent *) override
\reimp
void timerEvent(QTimerEvent *) override
\reimp
bool hitButton(const QPoint &pos) const override
\reimp
virtual void initStyleOption(QStyleOptionToolButton *option) const
Initialize option with the values from this QToolButton.
void paintEvent(QPaintEvent *) override
Paints the button in response to the paint event.
void mouseReleaseEvent(QMouseEvent *) override
\reimp
void setLayoutItemMargins(int left, int top, int right, int bottom)
QList< QAction * > actions
Definition qwidget_p.h:709
static QRect availableScreenGeometry(const QWidget *widget)
Definition qwidget_p.h:474
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the ...
virtual void leaveEvent(QEvent *event)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
Definition qwidget.cpp:9731
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
void setEnabled(bool)
Definition qwidget.cpp:3358
virtual void actionEvent(QActionEvent *event)
This event handler is called with the given event whenever the widget's actions are changed.
Definition qwidget.cpp:9835
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
QFontMetrics fontMetrics() const
Returns the font metrics for the widget's current font.
Definition qwidget.h:847
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget's actions.
Definition qwidget.cpp:3207
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
virtual void enterEvent(QEnterEvent *event)
This event handler can be reimplemented in a subclass to receive widget enter events which are passed...
Definition qwidget.cpp:9715
void update()
Updates the widget unless updates are disabled or the widget is hidden.
QStyle * style() const
Definition qwidget.cpp:2600
void setFont(const QFont &)
Definition qwidget.cpp:4667
QFont font
the font currently set for the widget
Definition qwidget.h:133
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
void removeAction(QAction *action)
Removes the action action from this widget's list of actions.
Definition qwidget.cpp:3186
bool isVisible() const
Definition qwidget.h:874
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
rect
[4]
QStyleOptionButton opt
Combined button and popup list for selecting options.
@ LeftButton
Definition qnamespace.h:58
@ WA_Hover
Definition qnamespace.h:340
@ TabFocus
Definition qnamespace.h:108
@ Vertical
Definition qnamespace.h:100
ArrowType
@ NoArrow
@ TextShowMnemonic
Definition qnamespace.h:173
ToolButtonStyle
@ ToolButtonTextOnly
@ ToolButtonTextUnderIcon
@ ToolButtonTextBesideIcon
@ ToolButtonIconOnly
@ ToolButtonFollowStyle
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLenum type
GLboolean enable
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
GLuint GLenum option
decorationRoleName toolTipRoleName setWhatsThis
decorationRoleName setToolTip
QScreen * screen
[1]
Definition main.cpp:29
#define emit
unsigned int uint
Definition qtypes.h:34
QObject::connect nullptr
QMenu menu
[5]