Qt 6.x
The Qt SDK
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 _q_buttonPressed();
43 void _q_buttonReleased();
44 void popupTimerDone();
45 void _q_updateButtonDown();
46 void _q_menuTriggered(QAction *);
47#endif
48 bool updateHoverControl(const QPoint &pos);
49 void _q_actionTriggered();
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
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)
190 QObject::connect(q, SIGNAL(pressed()), q, SLOT(_q_buttonPressed()));
191 QObject::connect(q, SIGNAL(released()), q, SLOT(_q_buttonReleased()));
192#endif
193
195 delay = q->style()->styleHint(QStyle::SH_ToolButton_PopupDelay, nullptr, q);
196}
197
206{
207 if (!option)
208 return;
209
210 Q_D(const QToolButton);
211 option->initFrom(this);
212 option->iconSize = iconSize(); //default value
213
214#if QT_CONFIG(toolbar)
215 if (parentWidget()) {
216 if (QToolBar *toolBar = qobject_cast<QToolBar *>(parentWidget())) {
217 option->iconSize = toolBar->iconSize();
218 }
219 }
220#endif // QT_CONFIG(toolbar)
221
222 option->text = d->text;
223 option->icon = d->icon;
224 option->arrowType = d->arrowType;
225 if (d->down)
227 if (d->checked)
228 option->state |= QStyle::State_On;
229 if (d->autoRaise)
231 if (!d->checked && !d->down)
233
234 option->subControls = QStyle::SC_ToolButton;
235 option->activeSubControls = QStyle::SC_None;
236
238 if (d->popupMode == QToolButton::MenuButtonPopup) {
239 option->subControls |= QStyle::SC_ToolButtonMenu;
241 }
242 if (option->state & QStyle::State_MouseOver) {
243 option->activeSubControls = d->hoverControl;
244 }
245 if (d->menuButtonDown) {
247 option->activeSubControls |= QStyle::SC_ToolButtonMenu;
248 }
249 if (d->down) {
251 option->activeSubControls |= QStyle::SC_ToolButton;
252 }
253
254
255 if (d->arrowType != Qt::NoArrow)
257 if (d->popupMode == QToolButton::DelayedPopup)
259#if QT_CONFIG(menu)
260 if (d->hasMenu())
262#endif
263 if (d->toolButtonStyle == Qt::ToolButtonFollowStyle) {
264 option->toolButtonStyle = Qt::ToolButtonStyle(style()->styleHint(QStyle::SH_ToolButtonStyle, option, this));
265 } else
266 option->toolButtonStyle = d->toolButtonStyle;
267
268 if (option->toolButtonStyle == Qt::ToolButtonTextBesideIcon) {
269 // If the action is not prioritized, remove the text label to save space
270 if (d->defaultAction && d->defaultAction->priority() < QAction::NormalPriority)
271 option->toolButtonStyle = Qt::ToolButtonIconOnly;
272 }
273
274 if (d->icon.isNull() && d->arrowType == Qt::NoArrow) {
275 if (!d->text.isEmpty())
276 option->toolButtonStyle = Qt::ToolButtonTextOnly;
277 else if (option->toolButtonStyle != Qt::ToolButtonTextOnly)
278 option->toolButtonStyle = Qt::ToolButtonIconOnly;
279 }
280
281 option->pos = pos();
282 option->font = font();
283}
284
290{
291}
292
297{
298 Q_D(const QToolButton);
299 if (d->sizeHint.isValid())
300 return d->sizeHint;
302
303 int w = 0, h = 0;
306
308 if (opt.toolButtonStyle != Qt::ToolButtonTextOnly) {
310 w = icon.width();
311 h = icon.height();
312 }
313
314 if (opt.toolButtonStyle != Qt::ToolButtonIconOnly) {
315 QSize textSize = fm.size(Qt::TextShowMnemonic, text());
316 textSize.setWidth(textSize.width() + fm.horizontalAdvance(u' ') * 2);
317 if (opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
318 h += 4 + textSize.height();
319 if (textSize.width() > w)
320 w = textSize.width();
321 } else if (opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon) {
322 w += 4 + textSize.width();
323 if (textSize.height() > h)
324 h = textSize.height();
325 } else { // TextOnly
326 w = textSize.width();
327 h = textSize.height();
328 }
329 }
330
331 opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height
332 if (d->popupMode == MenuButtonPopup)
334
335 d->sizeHint = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this);
336 return d->sizeHint;
337}
338
343{
344 return sizeHint();
345}
346
372{
373 Q_D(const QToolButton);
374 return d->toolButtonStyle;
375}
376
378{
379 Q_D(const QToolButton);
380 return d->arrowType;
381}
382
383
385{
386 Q_D(QToolButton);
387 if (d->toolButtonStyle == style)
388 return;
389
390 d->toolButtonStyle = style;
391 d->sizeHint = QSize();
393 if (isVisible()) {
394 update();
395 }
396}
397
399{
400 Q_D(QToolButton);
401 if (d->arrowType == type)
402 return;
403
404 d->arrowType = type;
405 d->sizeHint = QSize();
407 if (isVisible()) {
408 update();
409 }
410}
411
418{
419 QStylePainter p(this);
422 p.drawComplexControl(QStyle::CC_ToolButton, opt);
423}
424
429{
430 Q_D(QToolButton);
431 auto action = static_cast<QAction *>(event->action());
432 switch (event->type()) {
434 if (action == d->defaultAction)
435 setDefaultAction(action); // update button state
436 break;
438 connect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
439 break;
441 if (d->defaultAction == action)
442 d->defaultAction = nullptr;
443#if QT_CONFIG(menu)
444 if (action == d->menuAction)
445 d->menuAction = nullptr;
446#endif
447 action->disconnect(this);
448 break;
449 default:
450 ;
451 }
453}
454
456{
457 Q_Q(QToolButton);
459 q->initStyleOption(&opt);
460 opt.subControls = QStyle::SC_All;
461 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ToolButton, &opt, pos, q);
463 hoverRect = QRect();
464 else
465 hoverRect = q->style()->subControlRect(QStyle::CC_ToolButton, &opt, hoverControl, q);
466 return hoverControl;
467}
468
470{
471 Q_Q(QToolButton);
472 QRect lastHoverRect = hoverRect;
473 QStyle::SubControl lastHoverControl = hoverControl;
474 bool doesHover = q->testAttribute(Qt::WA_Hover);
475 if (lastHoverControl != newHoverControl(pos) && doesHover) {
476 q->update(lastHoverRect);
477 q->update(hoverRect);
478 return true;
479 }
480 return !doesHover;
481}
482
484{
485 Q_Q(QToolButton);
486 if (QAction *action = qobject_cast<QAction *>(q->sender()))
487 emit q->triggered(action);
488}
489
494{
495 Q_D(QToolButton);
496 if (d->autoRaise)
497 update();
498 if (d->defaultAction)
499 d->defaultAction->hover();
501}
502
503
508{
509 Q_D(QToolButton);
510 if (d->autoRaise)
511 update();
512
514}
515
516
521{
522#if QT_CONFIG(menu)
523 Q_D(QToolButton);
524 if (e->timerId() == d->popupTimer.timerId()) {
525 d->popupTimerDone();
526 return;
527 }
528#endif
530}
531
532
537{
538#if QT_CONFIG(toolbar)
539 Q_D(QToolButton);
540 if (e->type() == QEvent::ParentChange) {
541 if (qobject_cast<QToolBar*>(parentWidget()))
542 d->autoRaise = true;
543 } else if (e->type() == QEvent::StyleChange
544#ifdef Q_OS_MAC
545 || e->type() == QEvent::MacSizeChange
546#endif
547 ) {
548 d->delay = style()->styleHint(QStyle::SH_ToolButton_PopupDelay, nullptr, this);
549 d->setLayoutItemMargins(QStyle::SE_ToolButtonLayoutItem);
550 }
551#endif
553}
554
559{
560 Q_D(QToolButton);
561#if QT_CONFIG(menu)
564 if (e->button() == Qt::LeftButton && (d->popupMode == MenuButtonPopup)) {
567 if (popupr.isValid() && popupr.contains(e->position().toPoint())) {
569 showMenu();
570 return;
571 }
572 }
573#endif
576}
577
582{
583 Q_D(QToolButton);
585 d->buttonPressed = QToolButtonPrivate::NoButtonPressed;
586}
587
592{
593 Q_D(const QToolButton);
595 return (d->buttonPressed != QToolButtonPrivate::MenuButtonPressed);
596 return false;
597}
598
599
600#if QT_CONFIG(menu)
610void QToolButton::setMenu(QMenu* menu)
611{
612 Q_D(QToolButton);
613
614 if (d->menuAction == (menu ? menu->menuAction() : nullptr))
615 return;
616
617 if (d->menuAction)
618 removeAction(d->menuAction);
619
620 if (menu) {
621 d->menuAction = menu->menuAction();
622 addAction(d->menuAction);
623 } else {
624 d->menuAction = nullptr;
625 }
626
627 // changing the menu set may change the size hint, so reset it
628 d->sizeHint = QSize();
630 update();
631}
632
639QMenu* QToolButton::menu() const
640{
641 Q_D(const QToolButton);
642 if (d->menuAction)
643 return d->menuAction->menu();
644 return nullptr;
645}
646
652void QToolButton::showMenu()
653{
654 Q_D(QToolButton);
655 if (!d->hasMenu()) {
656 d->menuButtonDown = false;
657 return; // no menu to show
658 }
659 // prevent recursions spinning another event loop
660 if (d->menuButtonDown)
661 return;
662
663
664 d->menuButtonDown = true;
665 repaint();
666 d->popupTimer.stop();
667 d->popupTimerDone();
668}
669
670void QToolButtonPrivate::_q_buttonPressed()
671{
672 Q_Q(QToolButton);
673 if (!hasMenu())
674 return; // no menu to show
676 return;
677 else if (delay > 0 && popupMode == QToolButton::DelayedPopup)
679 else if (delay == 0 || popupMode == QToolButton::InstantPopup)
680 q->showMenu();
681}
682
683void QToolButtonPrivate::_q_buttonReleased()
684{
686}
687
688static QPoint positionMenu(const QToolButton *q, bool horizontal,
689 const QSize &sh)
690{
691 QPoint p;
692 const QRect rect = q->rect(); // Find screen via point in case of QGraphicsProxyWidget.
693 const QRect screen = QWidgetPrivate::availableScreenGeometry(q, q->mapToGlobal(rect.center()));
694 if (horizontal) {
695 if (q->isRightToLeft()) {
696 if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.bottom()) {
697 p = q->mapToGlobal(rect.bottomRight());
698 } else {
699 p = q->mapToGlobal(rect.topRight() - QPoint(0, sh.height()));
700 }
701 p.rx() -= sh.width();
702 } else {
703 if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.bottom()) {
704 p = q->mapToGlobal(rect.bottomLeft());
705 } else {
706 p = q->mapToGlobal(rect.topLeft() - QPoint(0, sh.height()));
707 }
708 }
709 } else {
710 if (q->isRightToLeft()) {
711 if (q->mapToGlobal(QPoint(rect.left(), 0)).x() - sh.width() <= screen.x()) {
712 p = q->mapToGlobal(rect.topRight());
713 } else {
714 p = q->mapToGlobal(rect.topLeft());
715 p.rx() -= sh.width();
716 }
717 } else {
718 if (q->mapToGlobal(QPoint(rect.right(), 0)).x() + sh.width() <= screen.right()) {
719 p = q->mapToGlobal(rect.topRight());
720 } else {
721 p = q->mapToGlobal(rect.topLeft() - QPoint(sh.width(), 0));
722 }
723 }
724 }
725 p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width()));
726 p.ry() += 1;
727 return p;
728}
729
730void QToolButtonPrivate::popupTimerDone()
731{
732 Q_Q(QToolButton);
734 if (!menuButtonDown && !down)
735 return;
736
737 menuButtonDown = true;
738 QPointer<QMenu> actualMenu;
739 bool mustDeleteActualMenu = false;
740 if (menuAction) {
741 actualMenu = menuAction->menu();
742 } else if (defaultAction && defaultAction->menu()) {
743 actualMenu = defaultAction->menu();
744 } else {
745 actualMenu = new QMenu(q);
746 mustDeleteActualMenu = true;
747 for (int i = 0; i < actions.size(); i++)
748 actualMenu->addAction(actions.at(i));
749 }
750 repeat = q->autoRepeat();
751 q->setAutoRepeat(false);
752 bool horizontal = true;
753#if QT_CONFIG(toolbar)
754 QToolBar *tb = qobject_cast<QToolBar*>(parent);
755 if (tb && tb->orientation() == Qt::Vertical)
756 horizontal = false;
757#endif
759 actualMenu->setNoReplayFor(q);
760 if (!mustDeleteActualMenu) //only if action are not in this widget
761 QObject::connect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*)));
762 QObject::connect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown()));
763 actualMenu->d_func()->causedPopup.widget = q;
764 actualMenu->d_func()->causedPopup.action = defaultAction;
765 actionsCopy = q->actions(); //(the list of action may be modified in slots)
766
767 // QTBUG-78966, Delay positioning until after aboutToShow().
768 auto positionFunction = [q, horizontal](const QSize &sizeHint) {
769 return positionMenu(q, horizontal, sizeHint); };
770 const auto initialPos = positionFunction(actualMenu->sizeHint());
771 actualMenu->d_func()->exec(initialPos, nullptr, positionFunction);
772
773 if (!that)
774 return;
775
776 QObject::disconnect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown()));
777 if (mustDeleteActualMenu)
778 delete actualMenu;
779 else
780 QObject::disconnect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*)));
781
782 actionsCopy.clear();
783
784 if (repeat)
785 q->setAutoRepeat(true);
786}
787
788void QToolButtonPrivate::_q_updateButtonDown()
789{
790 Q_Q(QToolButton);
791 menuButtonDown = false;
792 if (q->isDown())
793 q->setDown(false);
794 else
795 q->repaint();
796}
797
798void QToolButtonPrivate::_q_menuTriggered(QAction *action)
799{
800 Q_Q(QToolButton);
801 if (action && !actionsCopy.contains(action))
802 emit q->triggered(action);
803}
804
835void QToolButton::setPopupMode(ToolButtonPopupMode mode)
836{
837 Q_D(QToolButton);
838 d->popupMode = mode;
839}
840
841QToolButton::ToolButtonPopupMode QToolButton::popupMode() const
842{
843 Q_D(const QToolButton);
844 return d->popupMode;
845}
846#endif
847
857{
858 Q_D(QToolButton);
859 d->autoRaise = enable;
860
861 update();
862}
863
865{
866 Q_D(const QToolButton);
867 return d->autoRaise;
868}
869
893{
894 Q_D(QToolButton);
895#if QT_CONFIG(menu)
896 bool hadMenu = false;
897 hadMenu = d->hasMenu();
898#endif
899 d->defaultAction = action;
900 if (!action)
901 return;
902 if (!actions().contains(action))
903 addAction(action);
904 QString buttonText = action->iconText();
905 // If iconText() is generated from text(), we need to escape any '&'s so they
906 // don't turn into shortcuts
907 if (QActionPrivate::get(action)->iconText.isEmpty())
908 buttonText.replace("&"_L1, "&&"_L1);
909 setText(buttonText);
910 setIcon(action->icon());
911#if QT_CONFIG(tooltip)
912 setToolTip(action->toolTip());
913#endif
914#if QT_CONFIG(statustip)
915 setStatusTip(action->statusTip());
916#endif
917#if QT_CONFIG(whatsthis)
918 setWhatsThis(action->whatsThis());
919#endif
920#if QT_CONFIG(menu)
921 if (action->menu() && !hadMenu) {
922 // new 'default' popup mode defined introduced by tool bar. We
923 // should have changed QToolButton's default instead. Do that
924 // in 4.2.
925 setPopupMode(QToolButton::MenuButtonPopup);
926 }
927#endif
928 setCheckable(action->isCheckable());
929 setChecked(action->isChecked());
930 setEnabled(action->isEnabled());
931 if (action->d_func()->fontSet)
932 setFont(action->font());
933}
934
935
942{
943 Q_D(const QToolButton);
944 return d->defaultAction;
945}
946
951{
952 Q_D(QToolButton);
953 if (d->defaultAction && d->defaultAction->isCheckable())
954 d->defaultAction->setChecked(isChecked());
955}
956
961{
962 Q_D(QToolButton);
963 if (!d->defaultAction)
965 else
966 d->defaultAction->trigger();
967}
968
971{
972 switch(event->type()) {
976 if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
977 d_func()->updateHoverControl(he->position().toPoint());
978 break;
979 default:
980 break;
981 }
983}
984
986
987#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 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:45
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
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:164
\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
\reentrant \inmodule QtGui
QSize size(int flags, const QString &str, int tabstops=0, int *tabarray=nullptr) const
Returns the size in pixels of text.
int horizontalAdvance(const QString &, int len=-1) const
Returns the horizontal advance in pixels of the first len characters of text.
\inmodule QtGui
Definition qevent.h:245
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
QAction * menuAction() const
Returns the action associated with this menu.
Definition qmenu.cpp:1047
\inmodule QtGui
Definition qevent.h:195
QObject * parent
Definition qobject.h:61
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3099
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore
Definition qpointer.h:18
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:169
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
Definition qrect.h:386
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:851
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:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
Definition qsize.h:135
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QString & replace(qsizetype i, qsizetype len, QChar after)
Definition qstring.cpp:3794
\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:548
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:677
@ SH_ToolButton_PopupDelay
Definition qstyle.h:635
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:359
The QToolBar class provides a movable panel that contains a set of controls.
Definition qtoolbar.h:23
Qt::Orientation orientation
orientation of the toolbar
Definition qtoolbar.h:30
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 triggered(QAction *)
This signal is emitted when the given action is triggered.
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:701
static QRect availableScreenGeometry(const QWidget *widget)
Definition qwidget_p.h:468
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:9777
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
void setEnabled(bool)
Definition qwidget.cpp:3365
virtual void actionEvent(QActionEvent *event)
This event handler is called with the given event whenever the widget's actions are changed.
Definition qwidget.cpp:9881
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:3214
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:9761
void update()
Updates the widget unless updates are disabled or the widget is hidden.
QStyle * style() const
Definition qwidget.cpp:2607
void setFont(const QFont &)
Definition qwidget.cpp:4674
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:3193
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:3124
double e
rect
[4]
QStyleOptionButton opt
Combined button and popup list for selecting options.
@ LeftButton
Definition qnamespace.h:57
@ WA_Hover
Definition qnamespace.h:339
@ TabFocus
Definition qnamespace.h:107
@ Vertical
Definition qnamespace.h:99
ArrowType
@ NoArrow
@ TextShowMnemonic
Definition qnamespace.h:172
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
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
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:29
QObject::connect nullptr
QMenu menu
[5]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent