17#if QT_CONFIG(mainwindow)
25#include <private/qabstractbutton_p.h>
26#include <private/qaction_p.h>
29#include <private/qmenu_p.h>
42 void onButtonPressed();
43 void onButtonReleased();
44 void popupTimerDone();
45 void updateButtonDown();
46 void onMenuTriggered(
QAction *);
68 QList<QAction *> actionsCopy;
73bool QToolButtonPrivate::hasMenu()
const
171#if QT_CONFIG(toolbar)
172 if (qobject_cast<QToolBar*>(
parent))
191 this, &QToolButtonPrivate::onButtonPressed);
193 this, &QToolButtonPrivate::onButtonReleased);
216#if QT_CONFIG(toolbar)
219 option->iconSize = toolBar->iconSize();
226 option->arrowType =
d->arrowType;
233 if (!
d->checked && !
d->down)
245 option->activeSubControls =
d->hoverControl;
247 if (
d->menuButtonDown) {
268 option->toolButtonStyle =
d->toolButtonStyle;
277 if (!
d->text.isEmpty())
301 if (
d->sizeHint.isValid())
318 textSize.
setWidth(textSize.width() + fm.horizontalAdvance(u
' ') * 2);
320 h += 4 + textSize.height();
321 if (textSize.width() >
w)
322 w = textSize.width();
324 w += 4 + textSize.width();
325 if (textSize.height() >
h)
326 h = textSize.height();
328 w = textSize.width();
329 h = textSize.height();
376 return d->toolButtonStyle;
389 if (
d->toolButtonStyle ==
style)
392 d->toolButtonStyle =
style;
403 if (
d->arrowType ==
type)
433 auto action =
static_cast<QAction *
>(
event->action());
434 switch (
event->type()) {
436 if (action ==
d->defaultAction)
444 if (
d->defaultAction == action)
445 d->defaultAction =
nullptr;
447 if (action ==
d->menuAction)
448 d->menuAction =
nullptr;
450 action->disconnect(
this);
462 q->initStyleOption(&
opt);
479 q->update(lastHoverRect);
489 if (
QAction *action = qobject_cast<QAction *>(
q->sender()))
490 emit q->triggered(action);
501 if (
d->defaultAction)
502 d->defaultAction->hover();
527 if (e->
timerId() ==
d->popupTimer.timerId()) {
541#if QT_CONFIG(toolbar)
587 QPointer<QAbstractButton> guard(
this);
629 d->menuAction =
nullptr;
644QMenu* QToolButton::menu()
const
648 return d->menuAction->menu();
657void QToolButton::showMenu()
661 d->menuButtonDown =
false;
665 if (
d->menuButtonDown)
669 d->menuButtonDown =
true;
671 d->popupTimer.stop();
675void QToolButtonPrivate::onButtonPressed()
688void QToolButtonPrivate::onButtonReleased()
700 if (
q->isRightToLeft()) {
702 p =
q->mapToGlobal(
rect.bottomRight());
709 p =
q->mapToGlobal(
rect.bottomLeft());
715 if (
q->isRightToLeft()) {
717 p =
q->mapToGlobal(
rect.topRight());
719 p =
q->mapToGlobal(
rect.topLeft());
724 p =
q->mapToGlobal(
rect.topRight());
740void QToolButtonPrivate::popupTimerDone()
748 QPointer<QMenu> actualMenu;
749 bool mustDeleteActualMenu =
false;
755 actualMenu =
new QMenu(
q);
756 mustDeleteActualMenu =
true;
761 q->setAutoRepeat(
false);
762 bool horizontal =
true;
763#if QT_CONFIG(toolbar)
768 QPointer<QToolButton> that =
q;
769 actualMenu->setNoReplayFor(
q);
770 if (!mustDeleteActualMenu) {
772 this, &QToolButtonPrivate::onMenuTriggered);
775 this, &QToolButtonPrivate::updateButtonDown);
776 actualMenu->d_func()->causedPopup.widget =
q;
778 actionsCopy =
q->actions();
782 return positionMenu(
q, horizontal,
sizeHint); };
783 const auto initialPos = positionFunction(actualMenu->sizeHint());
784 actualMenu->d_func()->exec(initialPos,
nullptr, positionFunction);
790 this, &QToolButtonPrivate::updateButtonDown);
791 if (mustDeleteActualMenu) {
795 this, &QToolButtonPrivate::onMenuTriggered);
801 q->setAutoRepeat(
true);
804void QToolButtonPrivate::updateButtonDown()
814void QToolButtonPrivate::onMenuTriggered(
QAction *action)
817 if (action && !actionsCopy.contains(action))
818 emit q->triggered(action);
851void QToolButton::setPopupMode(ToolButtonPopupMode
mode)
912 bool hadMenu =
false;
913 hadMenu =
d->hasMenu();
915 d->defaultAction = action;
924 buttonText.
replace(
"&"_L1,
"&&"_L1);
927#if QT_CONFIG(tooltip)
930#if QT_CONFIG(statustip)
933#if QT_CONFIG(whatsthis)
937 if (action->
menu() && !hadMenu) {
947 if (action->d_func()->fontSet)
960 return d->defaultAction;
969 if (
d->defaultAction &&
d->defaultAction->isCheckable())
979 if (!
d->defaultAction)
982 d->defaultAction->trigger();
988 switch(
event->type()) {
993 d_func()->updateHoverControl(he->position().toPoint());
1003#include "moc_qtoolbutton.cpp"
The QActionEvent class provides an event that is generated when a QAction is added,...
static QActionPrivate * get(QAction *q)
The QAction class provides an abstraction for user commands that can be added to different user inter...
QString iconText
the action's descriptive icon text
T menu() const
Returns the menu contained by this action.
QString statusTip
the action's status tip
QString whatsThis
the action's "What's This?" help text
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
QString toolTip
the action's tooltip
QIcon icon
the action's icon
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
void stop()
Stops the timer.
Type type() const
Returns the event type.
\reentrant \inmodule QtGui
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
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)
static bool disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot)
The QPaintEvent class contains event parameters for paint events.
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Qt::MouseButton button() const
Returns the button that caused the event.
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & replace(qsizetype i, qsizetype len, QChar after)
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
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_ToolButton_PopupDelay
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...
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
SubControl
This enum describes the available sub controls.
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Combined button and popup list for selecting options.
@ ToolButtonTextUnderIcon
@ ToolButtonTextBesideIcon
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLfloat GLfloat GLfloat w
[0]
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
decorationRoleName toolTipRoleName setWhatsThis
decorationRoleName setToolTip