Qt 4.8
qtoolbutton.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qtoolbutton.h"
43 #ifndef QT_NO_TOOLBUTTON
44 
45 #include <qapplication.h>
46 #include <qdesktopwidget.h>
47 #include <qdrawutil.h>
48 #include <qevent.h>
49 #include <qicon.h>
50 #include <qmenu.h>
51 #include <qpainter.h>
52 #include <qpointer.h>
53 #include <qstyle.h>
54 #include <qstyleoption.h>
55 #include <qtooltip.h>
56 #include <qmainwindow.h>
57 #include <qtoolbar.h>
58 #include <qvariant.h>
59 #include <qstylepainter.h>
60 #include <private/qabstractbutton_p.h>
61 #include <private/qaction_p.h>
62 #include <private/qmenu_p.h>
63 
65 
67 {
69 public:
70  void init();
71 #ifndef QT_NO_MENU
72  void _q_buttonPressed();
73  void popupTimerDone();
74  void _q_updateButtonDown();
75  void _q_menuTriggered(QAction *);
76 #endif
77  bool updateHoverControl(const QPoint &pos);
78  void _q_actionTriggered();
82  QPointer<QAction> menuAction; //the menu set by the user (setMenu)
84  int delay;
92  uint repeat : 1;
94 #ifndef QT_NO_MENU
95  bool hasMenu() const;
96  //workaround for task 177850
98 #endif
99 #ifdef QT3_SUPPORT
100  bool userDefinedPopupDelay;
101 #endif
102 };
103 
104 #ifndef QT_NO_MENU
106 {
107  return ((defaultAction && defaultAction->menu())
108  || (menuAction && menuAction->menu())
109  || actions.size() > (defaultAction ? 1 : 0));
110 }
111 #endif
112 
193  : QAbstractButton(*new QToolButtonPrivate, parent)
194 {
195  Q_D(QToolButton);
196  d->init();
197 }
198 
199 #ifdef QT3_SUPPORT
200 
206  : QAbstractButton(*new QToolButtonPrivate, parent)
207 {
208  Q_D(QToolButton);
210  d->init();
211 }
212 
223 QToolButton::QToolButton(const QIcon& icon, const QString &textLabel,
224  const QString& statusTip,
225  QObject * receiver, const char *slot,
226  QWidget * parent, const char *name)
227  : QAbstractButton(*new QToolButtonPrivate, parent)
228 {
229  Q_D(QToolButton);
231  d->init();
232  setIcon(icon);
233  setText(textLabel);
234  if (receiver && slot)
235  connect(this, SIGNAL(clicked()), receiver, slot);
236 #ifndef QT_NO_TOOLTIP
237  if (!textLabel.isEmpty())
238  setToolTip(textLabel);
239 #endif
240 #ifndef QT_NO_STATUSTIP
241  if (!statusTip.isEmpty())
242  setStatusTip(statusTip);
243 #else
244  Q_UNUSED(statusTip);
245 #endif
246 }
247 
248 
260  : QAbstractButton(*new QToolButtonPrivate, parent)
261 {
262  Q_D(QToolButton);
264  d->init();
265  setAutoRepeat(true);
266  d->arrowType = type;
267 }
268 
269 #endif
270 
271 
272 /* Set-up code common to all the constructors */
273 
275 {
276  Q_Q(QToolButton);
277  delay = q->style()->styleHint(QStyle::SH_ToolButton_PopupDelay, 0, q);
278 #ifdef QT3_SUPPORT
279  userDefinedPopupDelay = false;
280 #endif
281  defaultAction = 0;
282 #ifndef QT_NO_TOOLBAR
283  if (qobject_cast<QToolBar*>(parent))
284  autoRaise = true;
285  else
286 #endif
287  autoRaise = false;
289  menuButtonDown = false;
291  buttonPressed = QToolButtonPrivate::NoButtonPressed;
292 
294  hoverControl = QStyle::SC_None;
295 
296  q->setFocusPolicy(Qt::TabFocus);
299 
300 #ifndef QT_NO_MENU
301  QObject::connect(q, SIGNAL(pressed()), q, SLOT(_q_buttonPressed()));
302 #endif
303 
305 
306 }
307 
316 {
317  if (!option)
318  return;
319 
320  Q_D(const QToolButton);
321  option->initFrom(this);
322  bool forceNoText = false;
323  option->iconSize = iconSize(); //default value
324 
325 #ifndef QT_NO_TOOLBAR
326  if (parentWidget()) {
327  if (QToolBar *toolBar = qobject_cast<QToolBar *>(parentWidget())) {
328  option->iconSize = toolBar->iconSize();
329  }
330 #ifdef QT3_SUPPORT
331  else if (parentWidget()->inherits("Q3ToolBar")) {
332  if (!option->iconSize.isValid()) {
333  int iconSize = style()->pixelMetric(QStyle::PM_ToolBarIconSize, option, this);
334  option->iconSize = d->icon.actualSize(QSize(iconSize, iconSize));
335  }
336  forceNoText = d->toolButtonStyle == Qt::ToolButtonIconOnly;
337  }
338 #endif
339  }
340 #endif // QT_NO_TOOLBAR
341 
342  if (!forceNoText)
343  option->text = d->text;
344  option->icon = d->icon;
345  option->arrowType = d->arrowType;
346  if (d->down)
347  option->state |= QStyle::State_Sunken;
348  if (d->checked)
349  option->state |= QStyle::State_On;
350  if (d->autoRaise)
351  option->state |= QStyle::State_AutoRaise;
352  if (!d->checked && !d->down)
353  option->state |= QStyle::State_Raised;
354 
357 
359  if (d->popupMode == QToolButton::MenuButtonPopup) {
362  }
363  if (option->state & QStyle::State_MouseOver) {
364  option->activeSubControls = d->hoverControl;
365  }
366  if (d->menuButtonDown) {
367  option->state |= QStyle::State_Sunken;
369  }
370  if (d->down) {
371  option->state |= QStyle::State_Sunken;
373  }
374 
375 
376  if (d->arrowType != Qt::NoArrow)
378  if (d->popupMode == QToolButton::DelayedPopup)
380 #ifndef QT_NO_MENU
381  if (d->hasMenu())
383 #endif
384  if (d->toolButtonStyle == Qt::ToolButtonFollowStyle) {
386  } else
387  option->toolButtonStyle = d->toolButtonStyle;
388 
390  // If the action is not prioritized, remove the text label to save space
391  if (d->defaultAction && d->defaultAction->priority() < QAction::NormalPriority)
393  }
394 
395  if (d->icon.isNull() && d->arrowType == Qt::NoArrow && !forceNoText) {
396  if (!d->text.isEmpty())
398  else if (option->toolButtonStyle != Qt::ToolButtonTextOnly)
400  }
401 
402  option->pos = pos();
403  option->font = font();
404 }
405 
411 {
412 }
413 
418 {
419  Q_D(const QToolButton);
420  if (d->sizeHint.isValid())
421  return d->sizeHint;
422  ensurePolished();
423 
424  int w = 0, h = 0;
426  initStyleOption(&opt);
427 
428  QFontMetrics fm = fontMetrics();
430  QSize icon = opt.iconSize;
431  w = icon.width();
432  h = icon.height();
433 #ifdef Q_WS_MAC
435  w /= qt_mac_get_scalefactor();
436  h /= qt_mac_get_scalefactor();
437 #endif
438  }
439 
441  QSize textSize = fm.size(Qt::TextShowMnemonic, text());
442  textSize.setWidth(textSize.width() + fm.width(QLatin1Char(' '))*2);
444  h += 4 + textSize.height();
445  if (textSize.width() > w)
446  w = textSize.width();
447  } else if (opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon) {
448  w += 4 + textSize.width();
449  if (textSize.height() > h)
450  h = textSize.height();
451  } else { // TextOnly
452  w = textSize.width();
453  h = textSize.height();
454  }
455  }
456 
457  opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height
458  if (d->popupMode == MenuButtonPopup)
459  w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this);
460 
461  d->sizeHint = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this).
462  expandedTo(QApplication::globalStrut());
463  return d->sizeHint;
464 }
465 
470 {
471  return sizeHint();
472 }
473 
520 {
521  Q_D(const QToolButton);
522  return d->toolButtonStyle;
523 }
524 
526 {
527  Q_D(const QToolButton);
528  return d->arrowType;
529 }
530 
531 
533 {
534  Q_D(QToolButton);
535  if (d->toolButtonStyle == style)
536  return;
537 
538  d->toolButtonStyle = style;
539  d->sizeHint = QSize();
540  updateGeometry();
541  if (isVisible()) {
542  update();
543  }
544 }
545 
547 {
548  Q_D(QToolButton);
549  if (d->arrowType == type)
550  return;
551 
552  d->arrowType = type;
553  d->sizeHint = QSize();
554  updateGeometry();
555  if (isVisible()) {
556  update();
557  }
558 }
559 
566 {
567  QStylePainter p(this);
569  initStyleOption(&opt);
571 }
572 
577 {
578  Q_D(QToolButton);
579  QAction *action = event->action();
580  switch (event->type()) {
582  if (action == d->defaultAction)
583  setDefaultAction(action); // update button state
584  break;
585  case QEvent::ActionAdded:
586  connect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
587  break;
589  if (d->defaultAction == action)
590  d->defaultAction = 0;
591 #ifndef QT_NO_MENU
592  if (action == d->menuAction)
593  d->menuAction = 0;
594 #endif
595  action->disconnect(this);
596  break;
597  default:
598  ;
599  }
601 }
602 
604 {
605  Q_Q(QToolButton);
607  q->initStyleOption(&opt);
609  hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ToolButton, &opt, pos, q);
610  if (hoverControl == QStyle::SC_None)
611  hoverRect = QRect();
612  else
613  hoverRect = q->style()->subControlRect(QStyle::CC_ToolButton, &opt, hoverControl, q);
614  return hoverControl;
615 }
616 
618 {
619  Q_Q(QToolButton);
620  QRect lastHoverRect = hoverRect;
621  QStyle::SubControl lastHoverControl = hoverControl;
622  bool doesHover = q->testAttribute(Qt::WA_Hover);
623  if (lastHoverControl != newHoverControl(pos) && doesHover) {
624  q->update(lastHoverRect);
625  q->update(hoverRect);
626  return true;
627  }
628  return !doesHover;
629 }
630 
632 {
633  Q_Q(QToolButton);
634  if (QAction *action = qobject_cast<QAction *>(q->sender()))
635  emit q->triggered(action);
636 }
637 
642 {
643  Q_D(QToolButton);
644  if (d->autoRaise)
645  update();
646  if (d->defaultAction)
647  d->defaultAction->hover();
649 }
650 
651 
656 {
657  Q_D(QToolButton);
658  if (d->autoRaise)
659  update();
660 
662 }
663 
664 
669 {
670 #ifndef QT_NO_MENU
671  Q_D(QToolButton);
672  if (e->timerId() == d->popupTimer.timerId()) {
673  d->popupTimerDone();
674  return;
675  }
676 #endif
678 }
679 
680 
685 {
686 #ifndef QT_NO_TOOLBAR
687  Q_D(QToolButton);
688  if (e->type() == QEvent::ParentChange) {
689  if (qobject_cast<QToolBar*>(parentWidget()))
690  d->autoRaise = true;
691  } else if (e->type() == QEvent::StyleChange
692 #ifdef Q_WS_MAC
693  || e->type() == QEvent::MacSizeChange
694 #endif
695  ) {
696 #ifdef QT3_SUPPORT
697  if (!d->userDefinedPopupDelay)
698 #endif
699  d->delay = style()->styleHint(QStyle::SH_ToolButton_PopupDelay, 0, this);
700  d->setLayoutItemMargins(QStyle::SE_ToolButtonLayoutItem);
701  }
702 #endif
704 }
705 
710 {
711  Q_D(QToolButton);
712 #ifndef QT_NO_MENU
714  initStyleOption(&opt);
715  if (e->button() == Qt::LeftButton && (d->popupMode == MenuButtonPopup)) {
718  if (popupr.isValid() && popupr.contains(e->pos())) {
719  d->buttonPressed = QToolButtonPrivate::MenuButtonPressed;
720  showMenu();
721  return;
722  }
723  }
724 #endif
725  d->buttonPressed = QToolButtonPrivate::ToolButtonPressed;
727 }
728 
733 {
734  Q_D(QToolButton);
736  d->buttonPressed = QToolButtonPrivate::NoButtonPressed;
737 }
738 
743 {
744  Q_D(const QToolButton);
746  return (d->buttonPressed != QToolButtonPrivate::MenuButtonPressed);
747  return false;
748 }
749 
750 #ifdef QT3_SUPPORT
751 
755 QIcon QToolButton::onIconSet() const
756 {
757  return icon();
758 }
759 
763 QIcon QToolButton::offIconSet() const
764 {
765  return icon();
766 }
767 
768 
777 void QToolButton::setOnIconSet(const QIcon& set)
778 {
779  setIcon(set);
780 }
781 
790 void QToolButton::setOffIconSet(const QIcon& set)
791 {
792  setIcon(set);
793 }
794 
795 
812 void QToolButton::setIconSet(const QIcon & set, bool /* on */)
813 {
815 }
816 
830 QIcon QToolButton::iconSet(bool /* on */) const
831 {
832  return QAbstractButton::icon();
833 }
834 
835 #endif
836 
837 #ifndef QT_NO_MENU
838 
848 {
849  Q_D(QToolButton);
850 
851  if (d->menuAction)
852  removeAction(d->menuAction);
853 
854  if (menu) {
855  d->menuAction = menu->menuAction();
856  addAction(d->menuAction);
857  } else {
858  d->menuAction = 0;
859  }
860  update();
861 }
862 
869 {
870  Q_D(const QToolButton);
871  if (d->menuAction)
872  return d->menuAction->menu();
873  return 0;
874 }
875 
882 {
883  Q_D(QToolButton);
884  if (!d->hasMenu()) {
885  d->menuButtonDown = false;
886  return; // no menu to show
887  }
888  // prevent recursions spinning another event loop
889  if (d->menuButtonDown)
890  return;
891 
892  d->menuButtonDown = true;
893  repaint();
894  d->popupTimer.stop();
895  d->popupTimerDone();
896 }
897 
899 {
900  Q_Q(QToolButton);
901  if (!hasMenu())
902  return; // no menu to show
904  return;
905  else if (delay > 0 && !popupTimer.isActive() && popupMode == QToolButton::DelayedPopup)
906  popupTimer.start(delay, q);
907  else if (delay == 0 || popupMode == QToolButton::InstantPopup)
908  q->showMenu();
909 }
910 
912 {
913  Q_Q(QToolButton);
914  popupTimer.stop();
915  if (!menuButtonDown && !down)
916  return;
917 
918  menuButtonDown = true;
919  QPointer<QMenu> actualMenu;
920  bool mustDeleteActualMenu = false;
921  if(menuAction) {
922  actualMenu = menuAction->menu();
923  } else if (defaultAction && defaultAction->menu()) {
924  actualMenu = defaultAction->menu();
925  } else {
926  actualMenu = new QMenu(q);
927  mustDeleteActualMenu = true;
928  for(int i = 0; i < actions.size(); i++)
929  actualMenu->addAction(actions.at(i));
930  }
931  repeat = q->autoRepeat();
932  q->setAutoRepeat(false);
933  bool horizontal = true;
934 #if !defined(QT_NO_TOOLBAR)
936  if (tb && tb->orientation() == Qt::Vertical)
937  horizontal = false;
938 #endif
939  QPoint p;
941  QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers(SIGNAL(aboutToShow()))? QSize() : actualMenu->sizeHint();
942  QRect rect = q->rect();
943  if (horizontal) {
944  if (q->isRightToLeft()) {
945  if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) {
946  p = q->mapToGlobal(rect.bottomRight());
947  } else {
948  p = q->mapToGlobal(rect.topRight() - QPoint(0, sh.height()));
949  }
950  p.rx() -= sh.width();
951  } else {
952  if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) {
953  p = q->mapToGlobal(rect.bottomLeft());
954  } else {
955  p = q->mapToGlobal(rect.topLeft() - QPoint(0, sh.height()));
956  }
957  }
958  } else {
959  if (q->isRightToLeft()) {
960  if (q->mapToGlobal(QPoint(rect.left(), 0)).x() - sh.width() <= screen.x()) {
961  p = q->mapToGlobal(rect.topRight());
962  } else {
963  p = q->mapToGlobal(rect.topLeft());
964  p.rx() -= sh.width();
965  }
966  } else {
967  if (q->mapToGlobal(QPoint(rect.right(), 0)).x() + sh.width() <= screen.right()) {
968  p = q->mapToGlobal(rect.topRight());
969  } else {
970  p = q->mapToGlobal(rect.topLeft() - QPoint(sh.width(), 0));
971  }
972  }
973  }
974  p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width()));
975  p.ry() += 1;
976  QPointer<QToolButton> that = q;
977  actualMenu->setNoReplayFor(q);
978  if (!mustDeleteActualMenu) //only if action are not in this widget
979  QObject::connect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*)));
980  QObject::connect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown()));
981  actualMenu->d_func()->causedPopup.widget = q;
982  actualMenu->d_func()->causedPopup.action = defaultAction;
983  actionsCopy = q->actions(); //(the list of action may be modified in slots)
984  actualMenu->exec(p);
985  QObject::disconnect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown()));
986  if (mustDeleteActualMenu)
987  delete actualMenu;
988  else
989  QObject::disconnect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*)));
990 
991  if (!that)
992  return;
993 
994  actionsCopy.clear();
995 
996  if (repeat)
997  q->setAutoRepeat(true);
998 }
999 
1001 {
1002  Q_Q(QToolButton);
1003  menuButtonDown = false;
1004  if (q->isDown())
1005  q->setDown(false);
1006  else
1007  q->repaint();
1008 }
1009 
1011 {
1012  Q_Q(QToolButton);
1013  if (action && !actionsCopy.contains(action))
1014  emit q->triggered(action);
1015 }
1016 #endif // QT_NO_MENU
1017 
1018 #ifdef QT3_SUPPORT
1019 
1027 void QToolButton::setPopupDelay(int delay)
1028 {
1029  Q_D(QToolButton);
1030  d->userDefinedPopupDelay = true;
1031  d->delay = delay;
1032 
1033  update();
1034 }
1035 
1039 int QToolButton::popupDelay() const
1040 {
1041  Q_D(const QToolButton);
1042  return d->delay;
1043 }
1044 #endif
1045 
1046 #ifndef QT_NO_MENU
1047 
1084 {
1085  Q_D(QToolButton);
1086  d->popupMode = mode;
1087 }
1088 
1090 {
1091  Q_D(const QToolButton);
1092  return d->popupMode;
1093 }
1094 #endif
1095 
1107 void QToolButton::setAutoRaise(bool enable)
1108 {
1109  Q_D(QToolButton);
1110  d->autoRaise = enable;
1111 
1112  update();
1113 }
1114 
1115 bool QToolButton::autoRaise() const
1116 {
1117  Q_D(const QToolButton);
1118  return d->autoRaise;
1119 }
1120 
1128 {
1129  Q_D(QToolButton);
1130 #ifndef QT_NO_MENU
1131  bool hadMenu = false;
1132  hadMenu = d->hasMenu();
1133 #endif
1134  d->defaultAction = action;
1135  if (!action)
1136  return;
1137  if (!actions().contains(action))
1138  addAction(action);
1139  setText(action->iconText());
1140  setIcon(action->icon());
1141 #ifndef QT_NO_TOOLTIP
1142  setToolTip(action->toolTip());
1143 #endif
1144 #ifndef QT_NO_STATUSTIP
1145  setStatusTip(action->statusTip());
1146 #endif
1147 #ifndef QT_NO_WHATSTHIS
1148  setWhatsThis(action->whatsThis());
1149 #endif
1150 #ifndef QT_NO_MENU
1151  if (action->menu() && !hadMenu) {
1152  // new 'default' popup mode defined introduced by tool bar. We
1153  // should have changed QToolButton's default instead. Do that
1154  // in 4.2.
1156  }
1157 #endif
1158  setCheckable(action->isCheckable());
1159  setChecked(action->isChecked());
1160  setEnabled(action->isEnabled());
1161  if (action->d_func()->fontSet)
1162  setFont(action->font());
1163 }
1164 
1165 
1172 {
1173  Q_D(const QToolButton);
1174  return d->defaultAction;
1175 }
1176 
1177 
1178 
1183 {
1184  Q_D(QToolButton);
1185  if (!d->defaultAction)
1187  else
1188  d->defaultAction->trigger();
1189 }
1190 
1193 {
1194  switch(event->type()) {
1195  case QEvent::HoverEnter:
1196  case QEvent::HoverLeave:
1197  case QEvent::HoverMove:
1198  if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
1199  d_func()->updateHoverControl(he->pos());
1200  break;
1201  default:
1202  break;
1203  }
1204  return QAbstractButton::event(event);
1205 }
1206 
1210  :QAbstractButton(dd, parent)
1211 {
1212  Q_D(QToolButton);
1213  d->init();
1214 }
1215 
1337 
1338 #include "moc_qtoolbutton.cpp"
1339 
1340 #endif
ToolButtonPopupMode
Describes how a menu should be popped up for tool buttons that has a menu set or contains a list of a...
Definition: qtoolbutton.h:71
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
QPoint pos() const
bool event(QEvent *e)
Reimplemented Function
double d
Definition: qnumeric_p.h:62
QBasicTimer popupTimer
Definition: qtoolbutton.cpp:83
void mousePressEvent(QMouseEvent *)
Reimplemented Function
void timerEvent(QTimerEvent *)
Reimplemented Function
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void setFont(const QFont &)
Use the single-argument overload instead.
Definition: qwidget.cpp:4996
bool isEnabled() const
Definition: qaction.cpp:1208
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
QStyle::SubControl hoverControl
Definition: qtoolbutton.cpp:80
int type
Definition: qmetatype.cpp:239
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
void setNoReplayFor(QWidget *widget)
Definition: qmenu.cpp:3164
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QString text() const
void setText(const QString &text)
bool updateHoverControl(const QPoint &pos)
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
Qt::ArrowType arrowType() const
Qt::ArrowType arrowType
the direction of the arrow for the tool button
Definition: qstyleoption.h:782
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=0) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
bool isVisible() const
Definition: qwidget.h:1005
void triggered(QAction *)
This signal is emitted when the given action is triggered.
static QSize globalStrut()
void setDefaultAction(QAction *)
Sets the default action to action.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
void timerEvent(QTimerEvent *e)
This event handler can be reimplemented in a subclass to receive timer events for the object...
The QHoverEvent class contains parameters that describe a mouse event.
Definition: qevent.h:125
CGFloat qt_mac_get_scalefactor()
void paintEvent(QPaintEvent *)
Paints the button in response to the paint event.
void showMenu()
Shows (pops up) the associated popup menu.
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual void leaveEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
Definition: qwidget.cpp:9491
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void _q_menuTriggered(QAction *)
QSize sizeHint() const
Reimplemented Function
Definition: qmenu.cpp:1805
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:143
void nextCheckState()
Reimplemented Function
QStyle::SubControl newHoverControl(const QPoint &pos)
The QActionEvent class provides an event that is generated when a QAction is added, removed, or changed.
Definition: qevent.h:632
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
Definition: qstyleoption.h:694
void pressed()
This signal is emitted when the button is pressed down.
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void actionEvent(QActionEvent *)
Reimplemented Function
~QToolButton()
Destroys the object and frees any allocated resources.
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
void setCheckable(bool)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
void addAction(QAction *action)
Appends the action action to this widget&#39;s list of actions.
Definition: qwidget.cpp:3317
The QStyleOptionToolButton class is used to describe the parameters for drawing a tool button...
Definition: qstyleoption.h:768
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
QStyle * style() const
Definition: qwidget.cpp:2742
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
void setAutoRepeat(bool)
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
QAbstractButton(QWidget *parent=0)
Constructs an abstract button with a parent.
void setWhatsThis(const QString &)
Definition: qwidget.cpp:11655
QToolButton::ToolButtonPopupMode popupMode
Definition: qtoolbutton.cpp:87
void changeEvent(QEvent *)
Reimplemented Function
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
#define SIGNAL(a)
Definition: qobjectdefs.h:227
bool event(QEvent *e)
Reimplemented Function
int width() const
Returns the width.
Definition: qsize.h:126
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QAction * defaultAction
Definition: qtoolbutton.cpp:93
Qt::ArrowType arrowType
Definition: qtoolbutton.cpp:85
Qt::ToolButtonStyle toolButtonStyle() const
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
QSize size(int flags, const QString &str, int tabstops=0, int *tabarray=0) const
Returns the size in pixels of text.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
virtual void nextCheckState()
This virtual handler is called when a button is clicked.
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
QPoint pos
the position of the tool button
Definition: qstyleoption.h:784
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
void setStatusTip(const QString &)
Definition: qwidget.cpp:11629
void leaveEvent(QEvent *)
Reimplemented Function
QFont font
the action&#39;s font
Definition: qaction.h:81
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
const char * styleHint(const QFontDef &request)
QIcon icon
the action&#39;s icon
Definition: qaction.h:75
int & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:140
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
int receivers(const char *signal) const
Returns the number of receivers connected to the signal.
Definition: qobject.cpp:2406
unsigned int uint
Definition: qglobal.h:996
virtual void actionEvent(QActionEvent *)
This event handler is called with the given event whenever the widget&#39;s actions are changed...
Definition: qwidget.cpp:9600
QString statusTip() const
QList< QAction * > actionsCopy
Definition: qtoolbutton.cpp:97
QToolButton(QWidget *parent=0)
Constructs an empty tool button with parent parent.
QString toolTip
the action&#39;s tooltip
Definition: qaction.h:78
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition: qobject.h:275
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
QRect rect() const
void setEnabled(bool)
Definition: qwidget.cpp:3447
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
QSize iconSize
the size of the icon for the tool button
Definition: qstyleoption.h:780
void setArrowType(Qt::ArrowType type)
void setToolTip(const QString &)
Definition: qwidget.cpp:11600
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
bool autoRepeat
whether the action can auto repeat
Definition: qaction.h:85
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
void repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the ...
Definition: qwidget.cpp:10761
QPoint topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:294
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
QAction * exec()
Executes this menu synchronously.
Definition: qmenu.cpp:2101
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QMenu * menu() const
Returns the menu contained by this action.
Definition: qaction.cpp:793
QSize iconSize() const
bool down
whether the button is pressed down
void mouseReleaseEvent(QMouseEvent *e)
Reimplemented Function
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QIcon icon
the icon for the tool button
Definition: qstyleoption.h:779
void changeEvent(QEvent *e)
Reimplemented Function
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QPoint bottomLeft() const
Returns the position of the rectangle&#39;s bottom-left corner.
Definition: qrect.h:297
Qt::ToolButtonStyle toolButtonStyle
a Qt::ToolButtonStyle value describing the appearance of the tool button
Definition: qstyleoption.h:783
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
ToolButtonFeatures features
an OR combination of the tool button&#39;s features
Definition: qstyleoption.h:778
Qt::ToolButtonStyle toolButtonStyle
Definition: qtoolbutton.cpp:86
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
Qt::Orientation orientation() const
orientation of the toolbar
Definition: qtoolbar.cpp:769
bool hasMenu() const
void setMenu(QMenu *menu)
Associates the given menu with this tool button.
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QMenu * menu() const
Returns the associated menu, or 0 if no menu has been defined.
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
Definition: qwidget.cpp:3386
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QString whatsThis
the action&#39;s "What&#39;s This?" help text
Definition: qaction.h:80
bool isCheckable() const
Definition: qaction.cpp:1105
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget&#39;s actions.
Definition: qwidget.cpp:3407
void setAutoRaise(bool enable)
int height() const
Returns the height.
Definition: qsize.h:129
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
QList< QAction * > actions
Definition: qwidget_p.h:760
void initStyleOption(QStyleOptionToolButton *option) const
Initialize option with the values from this QToolButton.
QString iconText
the action&#39;s descriptive icon text
Definition: qaction.h:77
bool isChecked() const
Definition: qaction.cpp:1151
void setPopupMode(ToolButtonPopupMode mode)
QObject * parent
Definition: qobject.h:92
void mouseReleaseEvent(QMouseEvent *)
Reimplemented Function
void enterEvent(QEvent *)
Reimplemented Function
QFont font
the font that is used for the text
Definition: qstyleoption.h:785
QPointer< QAction > menuAction
Definition: qtoolbutton.cpp:82
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55
The QBasicTimer class provides timer events for objects.
Definition: qbasictimer.h:55
const QFont & font() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
ToolButtonStyle
Definition: qnamespace.h:1572
void clicked(bool checked=false)
This signal is emitted when the button is activated (i.e.
QAction * menuAction() const
Returns the action associated with this menu.
Definition: qmenu.cpp:711
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QRect availableGeometry(int screen=-1) const
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
virtual bool hitButton(const QPoint &pos) const
Returns true if pos is inside the clickable button rectangle; otherwise returns false.
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:59
void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt)
Use the widget&#39;s style to draw a complex control cc specified by the QStyleOptionComplex option...
Definition: qstylepainter.h:92
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
void setIcon(const QIcon &icon)
static void setLayoutItemMargins(int left, int top, int right, int bottom, QRect *rect, Qt::LayoutDirection dir)
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
QString text
the text of the tool button
Definition: qstyleoption.h:781
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
bool hitButton(const QPoint &pos) const
Reimplemented Function
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
bool autoRaise() const
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
virtual void enterEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive widget enter events which are passed...
Definition: qwidget.cpp:9475
void setToolButtonStyle(Qt::ToolButtonStyle style)
QString statusTip
the action&#39;s status tip
Definition: qaction.h:79
QSize sizeHint() const
Reimplemented Function
void mousePressEvent(QMouseEvent *e)
Reimplemented Function
QIcon icon() const
ArrowType
Definition: qnamespace.h:1126
QSize minimumSizeHint() const
Reimplemented Function
QAction * defaultAction() const
Returns the default action.
ToolButtonPopupMode popupMode() const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
float CGFloat
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60