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 _q_buttonPressed();
43 void _q_buttonReleased();
44 void popupTimerDone();
45 void _q_updateButtonDown();
46 void _q_menuTriggered(
QAction *);
73bool QToolButtonPrivate::hasMenu()
const
171#if QT_CONFIG(toolbar)
172 if (qobject_cast<QToolBar*>(
parent))
214#if QT_CONFIG(toolbar)
217 option->iconSize = toolBar->iconSize();
224 option->arrowType =
d->arrowType;
231 if (!
d->checked && !
d->down)
243 option->activeSubControls =
d->hoverControl;
245 if (
d->menuButtonDown) {
266 option->toolButtonStyle =
d->toolButtonStyle;
275 if (!
d->text.isEmpty())
299 if (
d->sizeHint.isValid())
322 w += 4 + textSize.
width();
374 return d->toolButtonStyle;
387 if (
d->toolButtonStyle ==
style)
390 d->toolButtonStyle =
style;
401 if (
d->arrowType ==
type)
431 auto action =
static_cast<QAction *
>(
event->action());
432 switch (
event->type()) {
434 if (action ==
d->defaultAction)
441 if (
d->defaultAction == action)
442 d->defaultAction =
nullptr;
444 if (action ==
d->menuAction)
445 d->menuAction =
nullptr;
447 action->disconnect(
this);
459 q->initStyleOption(&
opt);
476 q->update(lastHoverRect);
486 if (
QAction *action = qobject_cast<QAction *>(
q->sender()))
487 emit q->triggered(action);
498 if (
d->defaultAction)
499 d->defaultAction->hover();
524 if (
e->timerId() ==
d->popupTimer.timerId()) {
538#if QT_CONFIG(toolbar)
624 d->menuAction =
nullptr;
639QMenu* QToolButton::menu()
const
643 return d->menuAction->menu();
652void QToolButton::showMenu()
656 d->menuButtonDown =
false;
660 if (
d->menuButtonDown)
664 d->menuButtonDown =
true;
666 d->popupTimer.stop();
670void QToolButtonPrivate::_q_buttonPressed()
683void QToolButtonPrivate::_q_buttonReleased()
695 if (
q->isRightToLeft()) {
697 p =
q->mapToGlobal(
rect.bottomRight());
704 p =
q->mapToGlobal(
rect.bottomLeft());
710 if (
q->isRightToLeft()) {
712 p =
q->mapToGlobal(
rect.topRight());
714 p =
q->mapToGlobal(
rect.topLeft());
719 p =
q->mapToGlobal(
rect.topRight());
730void QToolButtonPrivate::popupTimerDone()
739 bool mustDeleteActualMenu =
false;
745 actualMenu =
new QMenu(
q);
746 mustDeleteActualMenu =
true;
751 q->setAutoRepeat(
false);
752 bool horizontal =
true;
753#if QT_CONFIG(toolbar)
759 actualMenu->setNoReplayFor(
q);
760 if (!mustDeleteActualMenu)
763 actualMenu->d_func()->causedPopup.widget =
q;
765 actionsCopy =
q->actions();
769 return positionMenu(
q, horizontal,
sizeHint); };
770 const auto initialPos = positionFunction(actualMenu->sizeHint());
771 actualMenu->d_func()->exec(initialPos,
nullptr, positionFunction);
777 if (mustDeleteActualMenu)
785 q->setAutoRepeat(
true);
788void QToolButtonPrivate::_q_updateButtonDown()
798void QToolButtonPrivate::_q_menuTriggered(
QAction *action)
801 if (action && !actionsCopy.contains(action))
802 emit q->triggered(action);
835void QToolButton::setPopupMode(ToolButtonPopupMode
mode)
896 bool hadMenu =
false;
897 hadMenu =
d->hasMenu();
899 d->defaultAction = action;
908 buttonText.
replace(
"&"_L1,
"&&"_L1);
911#if QT_CONFIG(tooltip)
914#if QT_CONFIG(statustip)
917#if QT_CONFIG(whatsthis)
921 if (action->
menu() && !hadMenu) {
931 if (action->d_func()->fontSet)
944 return d->defaultAction;
953 if (
d->defaultAction &&
d->defaultAction->isCheckable())
963 if (!
d->defaultAction)
966 d->defaultAction->trigger();
972 switch(
event->type()) {
977 d_func()->updateHoverControl(he->position().toPoint());
987#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
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.
\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.
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
The QPaintEvent class contains event parameters for paint events.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
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...
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.
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
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent