Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qtoolbar.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 "qtoolbar.h"
5
6#include <qapplication.h>
7#if QT_CONFIG(combobox)
8#include <qcombobox.h>
9#endif
10#if QT_CONFIG(draganddrop)
11#include <qdrag.h>
12#endif
13#include <qevent.h>
14#include <qlayout.h>
15#include <qmainwindow.h>
16#include <qmenu.h>
17#if QT_CONFIG(menubar)
18#include <qmenubar.h>
19#endif
20#include <qmimedata.h>
21#if QT_CONFIG(rubberband)
22#include <qrubberband.h>
23#endif
24#include <qstylepainter.h>
25#include <qstyleoption.h>
26#include <qtoolbutton.h>
27#include <qwidgetaction.h>
28#include <qtimer.h>
29#include <private/qwidgetaction_p.h>
30#include <private/qmainwindowlayout_p.h>
31#include <private/qhighdpiscaling_p.h>
32
33#ifdef Q_OS_MACOS
34#include <qpa/qplatformnativeinterface.h>
35#endif
36
37#include "qtoolbar_p.h"
38#include "qtoolbarseparator_p.h"
39#include "qtoolbarlayout_p.h"
40
41#include "qdebug.h"
42
43#define POPUP_TIMER_INTERVAL 500
44
46
47using namespace Qt::StringLiterals;
48
49// qmainwindow.cpp
51
52/******************************************************************************
53** QToolBarPrivate
54*/
55
57{
58 Q_Q(QToolBar);
60 q->setBackgroundRole(QPalette::Button);
61 q->setAttribute(Qt::WA_Hover);
63
64 QStyle *style = q->style();
65 int e = style->pixelMetric(QStyle::PM_ToolBarIconSize, nullptr, q);
66 iconSize = QSize(e, e);
67
68 layout = new QToolBarLayout(q);
70
73 q->setMovable(q->style()->styleHint(QStyle::SH_ToolBar_Movable, nullptr, q ));
74 QObject::connect(toggleViewAction, SIGNAL(triggered(bool)), q, SLOT(_q_toggleView(bool)));
75}
76
78{
79 Q_Q(QToolBar);
80 if (b == q->isHidden()) {
81 if (b)
82 q->show();
83 else
84 q->close();
85 }
86}
87
89{
90 Q_Q(QToolBar);
91 if (!explicitIconSize) {
92 // iconSize not explicitly set
93 q->setIconSize(sz);
94 explicitIconSize = false;
95 }
96}
97
99{
100 Q_Q(QToolBar);
102 q->setToolButtonStyle(style);
104 }
105}
106
107void QToolBarPrivate::updateWindowFlags(bool floating, bool unplug)
108{
109 Q_Q(QToolBar);
110 Qt::WindowFlags flags = floating ? Qt::Tool : Qt::Widget;
111
113
114 // If we are performing a platform drag the flag is not needed and we want to avoid recreating
115 // the platform window when it would be removed later
116 if (unplug && !QMainWindowLayout::needsPlatformDrag())
118
119 q->setWindowFlags(flags);
120}
121
122void QToolBarPrivate::setWindowState(bool floating, bool unplug, const QRect &rect)
123{
124 Q_Q(QToolBar);
125 bool visible = !q->isHidden();
126 bool wasFloating = q->isFloating(); // ...is also currently using popup menus
127
128 updateWindowFlags(floating, unplug);
129
130 if (floating != wasFloating)
132
133 if (!rect.isNull())
134 q->setGeometry(rect);
135
136 if (visible)
137 q->show();
138
139 if (floating != wasFloating)
140 emit q->topLevelChanged(floating);
141}
142
144{
145 Q_Q(QToolBar);
146
147 if (state != nullptr)
148 return;
149
150 QMainWindow *win = qobject_cast<QMainWindow*>(parent);
151 Q_ASSERT(win != nullptr);
153 Q_ASSERT(layout != nullptr);
154 if (layout->pluggingWidget != nullptr) // the main window is animating a docking operation
155 return;
156
157 state = new DragState;
158 state->pressPos = pos;
159 state->dragging = false;
160 state->moving = false;
161 state->widgetItem = nullptr;
162
163 if (q->isRightToLeft())
164 state->pressPos = QPoint(q->width() - state->pressPos.x(), state->pressPos.y());
165}
166
168{
169 Q_Q(QToolBar);
170
171 Q_ASSERT(state != nullptr);
172
173 if ((moving && state->moving) || state->dragging)
174 return;
175
176 QMainWindow *win = qobject_cast<QMainWindow*>(parent);
177 Q_ASSERT(win != nullptr);
179 Q_ASSERT(layout != nullptr);
180
181 const bool wasFloating = q->isFloating();
182
183 if (!moving) {
184 state->widgetItem = layout->unplug(q);
185 Q_ASSERT(state->widgetItem != nullptr);
186 }
187 state->dragging = !moving;
188 state->moving = moving;
189
190#if QT_CONFIG(draganddrop)
191 if (QMainWindowLayout::needsPlatformDrag() && state->dragging) {
192 auto result = layout->performPlatformWidgetDrag(state->widgetItem, state->pressPos);
193 if (result == Qt::IgnoreAction && !wasFloating) {
194 layout->revert(state->widgetItem);
195 delete state;
196 state = nullptr;
197 } else {
198 endDrag();
199 }
200 }
201#endif
202}
203
205{
206 Q_Q(QToolBar);
207 Q_ASSERT(state != nullptr);
208
209 q->releaseMouse();
210
211 if (state->dragging) {
212 QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
213 Q_ASSERT(layout != nullptr);
214
215 if (!layout->plug(state->widgetItem)) {
216 if (q->isFloatable()) {
217 layout->restore();
218 setWindowState(true); // gets rid of the X11BypassWindowManager window flag
219 // and activates the resizer
220 q->activateWindow();
221 } else {
222 layout->revert(state->widgetItem);
223 }
224 }
225 }
226
227 delete state;
228 state = nullptr;
229}
230
232{
233 Q_Q(QToolBar);
234 QStyleOptionToolBar opt;
235 q->initStyleOption(&opt);
236 if (q->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, q).contains(event->position().toPoint()) == false) {
237#ifdef Q_OS_MACOS
238 // When using the unified toolbar on OS X, the user can click and
239 // drag between toolbar contents to move the window. Make this work by
240 // implementing the standard mouse-dragging code and then call
241 // window->move() in mouseMoveEvent below.
242 if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parent)) {
243 if (mainWindow->toolBarArea(q) == Qt::TopToolBarArea
244 && mainWindow->unifiedTitleAndToolBarOnMac()
245 && q->childAt(event->pos()) == 0) {
246 macWindowDragging = true;
247 macWindowDragPressPosition = event->pos();
248 return true;
249 }
250 }
251#endif
252 return false;
253 }
254
255 if (event->button() != Qt::LeftButton)
256 return true;
257
258 if (!layout->movable())
259 return true;
260
261 initDrag(event->position().toPoint());
262 return true;
263}
264
266{
267 // if we are peforming a platform drag ignore the release here and end the drag when the actual
268 // drag ends.
269 if (QMainWindowLayout::needsPlatformDrag())
270 return false;
271
272 if (state != nullptr) {
273 endDrag();
274 return true;
275 } else {
276#ifdef Q_OS_MACOS
277 if (!macWindowDragging)
278 return false;
279 macWindowDragging = false;
280 macWindowDragPressPosition = QPoint();
281 return true;
282#endif
283 return false;
284 }
285}
286
288{
289 Q_Q(QToolBar);
290
291 if (!state) {
292#ifdef Q_OS_MACOS
293 if (!macWindowDragging)
294 return false;
295 QWidget *w = q->window();
296 const QPoint delta = event->pos() - macWindowDragPressPosition;
297 w->move(w->pos() + delta);
298 return true;
299#endif
300 return false;
301 }
302
303 QMainWindow *win = qobject_cast<QMainWindow*>(parent);
304 if (win == nullptr)
305 return true;
306
308 Q_ASSERT(layout != nullptr);
309
310 if (layout->pluggingWidget == nullptr
311 && (event->position().toPoint() - state->pressPos).manhattanLength() > QApplication::startDragDistance()) {
312 const bool wasDragging = state->dragging;
313 const bool moving = !q->isWindow() && (orientation == Qt::Vertical ?
314 event->position().toPoint().x() >= 0 && event->position().toPoint().x() < q->width() :
315 event->position().toPoint().y() >= 0 && event->position().toPoint().y() < q->height());
316
317 startDrag(moving);
318 if (!moving && !wasDragging)
319 q->grabMouse();
320 }
321
322 if (!state) {
323 q->releaseMouse();
324 return true;
325 }
326
327 if (state->dragging) {
328 QPoint pos = event->globalPosition().toPoint();
329 // if we are right-to-left, we move so as to keep the right edge the same distance
330 // from the mouse
331 if (q->isLeftToRight())
332 pos -= state->pressPos;
333 else
334 pos += QPoint(state->pressPos.x() - q->width(), -state->pressPos.y());
335
336 q->move(pos);
337 layout->hover(state->widgetItem, event->globalPosition().toPoint());
338 } else if (state->moving) {
339
340 const QPoint rtl(q->width() - state->pressPos.x(), state->pressPos.y()); //for RTL
341 const QPoint globalPressPos = q->mapToGlobal(q->isRightToLeft() ? rtl : state->pressPos);
342 int pos = 0;
343
344 const QWindow *handle = q->window() ? q->window()->windowHandle() : nullptr;
345 const QPoint delta = handle
346 ? QHighDpi::fromNativePixels(event->globalPosition(), handle).toPoint()
347 - QHighDpi::fromNativePixels(globalPressPos, handle)
348 : event->globalPosition().toPoint() - globalPressPos;
349
350 if (orientation == Qt::Vertical) {
351 pos = q->y() + delta.y();
352 } else {
353 if (q->isRightToLeft()) {
354 pos = win->width() - q->width() - q->x() - delta.x();
355 } else {
356 pos = q->x() + delta.x();
357 }
358 }
359
360 layout->moveToolBar(q, pos);
361 }
362 return true;
363}
364
366{
367 Q_Q(QToolBar);
368 QRect r = _r;
369 r.moveTopLeft(q->mapToGlobal(QPoint(0, 0)));
370 setWindowState(true, true, r);
371 layout->setExpanded(false);
372}
373
375{
376 setWindowState(false, false, r);
377}
378
379/******************************************************************************
380** QToolBar
381*/
382
507 : QWidget(*new QToolBarPrivate, parent, { })
508{
509 Q_D(QToolBar);
510 d->init();
511}
512
523{
525}
526
527
532{
533}
534
547void QToolBar::setMovable(bool movable)
548{
549 Q_D(QToolBar);
550 if (!movable == !d->movable)
551 return;
552 d->movable = movable;
553 d->layout->invalidate();
554 emit movableChanged(d->movable);
555}
556
558{
559 Q_D(const QToolBar);
560 return d->movable;
561}
562
570{
571 Q_D(const QToolBar);
572 return d->floatable;
573}
574
575void QToolBar::setFloatable(bool floatable)
576{
577 Q_D(QToolBar);
578 d->floatable = floatable;
579}
580
590{
591 return isWindow();
592}
593
606void QToolBar::setAllowedAreas(Qt::ToolBarAreas areas)
607{
608 Q_D(QToolBar);
609 areas &= Qt::ToolBarArea_Mask;
610 if (areas == d->allowedAreas)
611 return;
612 d->allowedAreas = areas;
613 emit allowedAreasChanged(d->allowedAreas);
614}
615
616Qt::ToolBarAreas QToolBar::allowedAreas() const
617{
618 Q_D(const QToolBar);
619 return d->allowedAreas;
620}
621
634{
635 Q_D(QToolBar);
636 if (orientation == d->orientation)
637 return;
638
639 d->orientation = orientation;
640
643 else
645
646 d->layout->invalidate();
647 d->layout->activate();
648
649 emit orientationChanged(d->orientation);
650}
651
653{ Q_D(const QToolBar); return d->orientation; }
654
666{ Q_D(const QToolBar); return d->iconSize; }
667
669{
670 Q_D(QToolBar);
671 QSize sz = iconSize;
672 if (!sz.isValid()) {
673 QMainWindow *mw = qobject_cast<QMainWindow *>(parentWidget());
674 if (mw && mw->layout()) {
675 QLayout *layout = mw->layout();
676 int i = 0;
677 QLayoutItem *item = nullptr;
678 do {
679 item = layout->itemAt(i++);
680 if (item && (item->widget() == this))
681 sz = mw->iconSize();
682 } while (!sz.isValid() && item != nullptr);
683 }
684 }
685 if (!sz.isValid()) {
686 const int metric = style()->pixelMetric(QStyle::PM_ToolBarIconSize, nullptr, this);
687 sz = QSize(metric, metric);
688 }
689 if (d->iconSize != sz) {
690 d->iconSize = sz;
691 setMinimumSize(0, 0);
692 emit iconSizeChanged(d->iconSize);
693 }
694 d->explicitIconSize = iconSize.isValid();
695
696 d->layout->invalidate();
697}
698
715{ Q_D(const QToolBar); return d->toolButtonStyle; }
716
718{
719 Q_D(QToolBar);
720 d->explicitToolButtonStyle = true;
721 if (d->toolButtonStyle == toolButtonStyle)
722 return;
723 d->toolButtonStyle = toolButtonStyle;
724 setMinimumSize(0, 0);
725 emit toolButtonStyleChanged(d->toolButtonStyle);
726}
727
734{
736 for(int i = 0; i < actions.size(); i++)
738}
739
746{
747 QAction *action = new QAction(this);
748 action->setSeparator(true);
749 addAction(action);
750 return action;
751}
752
760{
761 QAction *action = new QAction(this);
762 action->setSeparator(true);
763 insertAction(before, action);
764 return action;
765}
766
783{
784 QWidgetAction *action = new QWidgetAction(this);
785 action->setDefaultWidget(widget);
786 action->d_func()->autoCreated = true;
787 addAction(action);
788 return action;
789}
790
802{
803 QWidgetAction *action = new QWidgetAction(this);
804 action->setDefaultWidget(widget);
805 action->d_func()->autoCreated = true;
806 insertAction(before, action);
807 return action;
808}
809
817{
818 Q_D(const QToolBar);
819
820 int index = d->layout->indexOf(action);
821 if (index == -1)
822 return QRect();
823 return d->layout->itemAt(index)->widget()->geometry();
824}
825
833{
834 Q_D(const QToolBar);
836 int index = d->layout->indexOf(widget);
837 if (index == -1)
838 return nullptr;
839 QLayoutItem *item = d->layout->itemAt(index);
840 return static_cast<QToolBarItem*>(item)->action;
841}
842
852{
853 Q_D(QToolBar);
854 auto action = static_cast<QAction *>(event->action());
855 QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(action);
856
857 switch (event->type()) {
858 case QEvent::ActionAdded: {
859 Q_ASSERT_X(widgetAction == nullptr || d->layout->indexOf(widgetAction) == -1,
860 "QToolBar", "widgets cannot be inserted multiple times");
861
862 // reparent the action to this toolbar if it has been created
863 // using the addAction(text) etc. convenience functions, to
864 // preserve Qt 4.1.x behavior. The widget is already
865 // reparented to us due to the createWidget call inside
866 // createItem()
867 if (widgetAction != nullptr && widgetAction->d_func()->autoCreated)
868 widgetAction->setParent(this);
869
870 int index = d->layout->count();
871 if (event->before()) {
872 index = d->layout->indexOf(event->before());
873 Q_ASSERT_X(index != -1, "QToolBar::insertAction", "internal error");
874 }
875 d->layout->insertAction(index, action);
876 break;
877 }
878
880 d->layout->invalidate();
881 break;
882
884 int index = d->layout->indexOf(action);
885 if (index != -1) {
886 delete d->layout->takeAt(index);
887 }
888 break;
889 }
890
891 default:
892 Q_ASSERT_X(false, "QToolBar::actionEvent", "internal error");
893 }
894}
895
898{
899 Q_D(QToolBar);
900 switch (event->type()) {
902 d->toggleViewAction->setText(windowTitle());
903 break;
905 d->layout->invalidate();
906 if (!d->explicitIconSize)
908 d->layout->updateMarginAndSpacing();
909 break;
911 d->layout->invalidate();
912 break;
913 default:
914 break;
915 }
917}
918
921{
922 Q_D(QToolBar);
923
924 QPainter p(this);
925 QStyle *style = this->style();
926 QStyleOptionToolBar opt;
928
929 if (d->layout->expanded || d->layout->animating || isWindow()) {
930 //if the toolbar is expended, we need to fill the background with the window color
931 //because some styles may expects that.
932 p.fillRect(opt.rect, palette().window());
935 } else {
937 }
938
940 if (opt.rect.isValid())
942}
943
944/*
945 Checks if an expanded toolbar has to wait for this popup to close before
946 the toolbar collapses. This is true if
947 1) the popup has the toolbar in its parent chain,
948 2) the popup is a menu whose menuAction is somewhere in the toolbar.
949*/
950static bool waitForPopup(QToolBar *tb, QWidget *popup)
951{
952 if (popup == nullptr || popup->isHidden())
953 return false;
954
955 QWidget *w = popup;
956 while (w != nullptr) {
957 if (w == tb)
958 return true;
959 w = w->parentWidget();
960 }
961
962 QMenu *menu = qobject_cast<QMenu*>(popup);
963 if (menu == nullptr)
964 return false;
965
966 const QAction *action = menu->menuAction();
967 for (auto object : action->associatedObjects()) {
968 if (QWidget *widget = qobject_cast<QWidget*>(object)) {
969 if (waitForPopup(tb, widget))
970 return true;
971 }
972 }
973
974 return false;
975}
976
977#ifdef Q_OS_MACOS
978static void enableMacToolBar(QToolBar *toolbar, bool enable)
979{
981 if (!nativeInterface)
982 return;
984 nativeInterface->nativeResourceFunctionForIntegration("setContentBorderAreaEnabled");
985 if (!function)
986 return; // Not Cocoa platform plugin.
987
988 typedef void (*SetContentBorderAreaEnabledFunction)(QWindow *window, void *identifier, bool enabled);
989 (reinterpret_cast<SetContentBorderAreaEnabledFunction>(function))(toolbar->window()->windowHandle(), toolbar, enable);
990}
991#endif
992
993
996{
997 Q_D(QToolBar);
998
999 switch (event->type()) {
1000 case QEvent::Timer:
1001 if (d->waitForPopupTimer.timerId() == static_cast<QTimerEvent*>(event)->timerId()) {
1003 if (!waitForPopup(this, w)) {
1004 d->waitForPopupTimer.stop();
1005 if (!this->underMouse())
1006 d->layout->setExpanded(false);
1007 }
1008 }
1009 break;
1010 case QEvent::Hide:
1011 if (!isHidden())
1012 break;
1013 Q_FALLTHROUGH();
1014 case QEvent::Show:
1015 d->toggleViewAction->setChecked(event->type() == QEvent::Show);
1016#ifdef Q_OS_MACOS
1017 enableMacToolBar(this, event->type() == QEvent::Show);
1018#endif
1020 break;
1022 d->layout->checkUsePopupMenu();
1023 break;
1024
1026 if (d->mousePressEvent(static_cast<QMouseEvent*>(event)))
1027 return true;
1028 break;
1029 }
1031 if (d->mouseReleaseEvent(static_cast<QMouseEvent*>(event)))
1032 return true;
1033 break;
1034 case QEvent::HoverEnter:
1035 case QEvent::HoverLeave:
1036 // there's nothing special to do here and we don't want to update the whole widget
1037 return true;
1038 case QEvent::HoverMove: {
1039#ifndef QT_NO_CURSOR
1040 QHoverEvent *e = static_cast<QHoverEvent*>(event);
1041 QStyleOptionToolBar opt;
1043 if (style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, this).contains(e->position().toPoint()))
1045 else
1046 unsetCursor();
1047#endif
1048 break;
1049 }
1050 case QEvent::MouseMove:
1051 if (d->mouseMoveEvent(static_cast<QMouseEvent*>(event)))
1052 return true;
1053 break;
1054 case QEvent::Leave:
1055 if (d->state != nullptr && d->state->dragging) {
1056#ifdef Q_OS_WIN
1057 // This is a workaround for losing the mouse on Vista.
1061 d->mouseMoveEvent(&fake);
1062#endif
1063 } else {
1064 if (!d->layout->expanded)
1065 break;
1066
1068 if (waitForPopup(this, w)) {
1069 d->waitForPopupTimer.start(POPUP_TIMER_INTERVAL, this);
1070 break;
1071 }
1072
1073 d->waitForPopupTimer.stop();
1074 d->layout->setExpanded(false);
1075 break;
1076 }
1077 default:
1078 break;
1079 }
1080 return QWidget::event(event);
1081}
1082
1092{ Q_D(const QToolBar); return d->toggleViewAction; }
1093
1102{
1103 Q_D(const QToolBar);
1104
1105 int index = d->layout->indexOf(action);
1106 if (index == -1)
1107 return nullptr;
1108
1109 return d->layout->itemAt(index)->widget();
1110}
1111
1113
1117void QToolBar::initStyleOption(QStyleOptionToolBar *option) const
1118{
1119 Q_D(const QToolBar);
1120
1121 if (!option)
1122 return;
1123
1124 option->initFrom(this);
1125 if (orientation() == Qt::Horizontal)
1127 option->lineWidth = style()->pixelMetric(QStyle::PM_ToolBarFrameWidth, nullptr, this);
1128 option->features = d->layout->movable()
1129 ? QStyleOptionToolBar::Movable
1130 : QStyleOptionToolBar::None;
1131 // if the tool bar is not in a QMainWindow, this will make the painting right
1132 option->toolBarArea = Qt::NoToolBarArea;
1133
1134 // Add more styleoptions if the toolbar has been added to a mainwindow.
1135 QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
1136
1137 if (!mainWindow)
1138 return;
1139
1141 Q_ASSERT_X(layout != nullptr, "QToolBar::initStyleOption()",
1142 "QMainWindow->layout() != QMainWindowLayout");
1143
1144 layout->getStyleOptionInfo(option, const_cast<QToolBar *>(this));
1145}
1146
1148
1149#include "moc_qtoolbar.cpp"
The QActionEvent class provides an event that is generated when a QAction is added,...
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
QList< QObject * > associatedObjects() const
Definition qaction.cpp:505
void setSeparator(bool b)
If b is true then this action will be considered a separator.
Definition qaction.cpp:569
void setCheckable(bool)
Definition qaction.cpp:832
static QWidget * activePopupWidget()
Returns the active popup widget.
int startDragDistance
the minimum distance required for a drag and drop operation to start.
static QPoint pos()
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.
Definition qcursor.cpp:188
\inmodule QtCore
Definition qcoreevent.h:45
@ ActionRemoved
Definition qcoreevent.h:153
@ ParentChange
Definition qcoreevent.h:80
@ ActionAdded
Definition qcoreevent.h:152
@ LayoutDirectionChange
Definition qcoreevent.h:124
@ StyleChange
Definition qcoreevent.h:136
@ ActionChanged
Definition qcoreevent.h:151
@ MouseMove
Definition qcoreevent.h:63
@ MouseButtonPress
Definition qcoreevent.h:60
@ HoverLeave
Definition qcoreevent.h:176
@ HoverEnter
Definition qcoreevent.h:175
@ HoverMove
Definition qcoreevent.h:177
@ WindowTitleChange
Definition qcoreevent.h:88
@ MouseButtonRelease
Definition qcoreevent.h:61
Type type() const
Returns the event type.
Definition qcoreevent.h:299
static QPlatformNativeInterface * platformNativeInterface()
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
static Qt::MouseButtons mouseButtons()
Returns the current state of the buttons on the mouse.
\inmodule QtGui
Definition qevent.h:245
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition qlayoutitem.h:25
The QLayout class is the base class of geometry managers.
Definition qlayout.h:26
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
The QMainWindow class provides a main application window.
Definition qmainwindow.h:25
QSize iconSize
size of toolbar icons in this mainwindow.
Definition qmainwindow.h:28
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
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2142
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPlatformNativeInterface class provides an abstraction for retrieving native resource handles.
virtual NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource)
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:127
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:132
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void moveTopLeft(const QPoint &p) noexcept
Moves the rectangle, leaving the top-left corner at the given position.
Definition qrect.h:303
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:169
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:126
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
@ State_Horizontal
Definition qstyle.h:74
@ SH_ToolBar_Movable
Definition qstyle.h:670
@ CE_ToolBar
Definition qstyle.h:223
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=nullptr) const =0
Returns the sub-area for the given element as described in the provided style option.
@ PM_ToolBarIconSize
Definition qstyle.h:490
@ PM_ToolBarFrameWidth
Definition qstyle.h:481
@ PE_IndicatorToolBarHandle
Definition qstyle.h:141
@ PE_FrameMenu
Definition qstyle.h:109
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given element with the provided painter with the style options specified by option.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
@ SE_ToolBarHandle
Definition qstyle.h:314
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
\inmodule QtCore
Definition qcoreevent.h:359
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition qcoreevent.h:363
void setExpanded(bool b)
void updateMarginAndSpacing()
bool movable() const
bool explicitToolButtonStyle
Definition qtoolbar_p.h:53
Qt::Orientation orientation
Definition qtoolbar_p.h:57
void plug(const QRect &r)
Definition qtoolbar.cpp:374
void updateWindowFlags(bool floating, bool unplug=false)
Definition qtoolbar.cpp:107
void startDrag(bool moving=false)
Definition qtoolbar.cpp:167
bool mousePressEvent(QMouseEvent *e)
Definition qtoolbar.cpp:231
void unplug(const QRect &r)
Definition qtoolbar.cpp:365
QToolBarLayout * layout
Definition qtoolbar_p.h:63
void _q_toggleView(bool b)
Definition qtoolbar.cpp:77
void setWindowState(bool floating, bool unplug=false, const QRect &rect=QRect())
Definition qtoolbar.cpp:122
bool mouseMoveEvent(QMouseEvent *e)
Definition qtoolbar.cpp:287
bool explicitIconSize
Definition qtoolbar_p.h:52
void _q_updateToolButtonStyle(Qt::ToolButtonStyle style)
Definition qtoolbar.cpp:98
bool mouseReleaseEvent(QMouseEvent *e)
Definition qtoolbar.cpp:265
DragState * state
Definition qtoolbar_p.h:71
void initDrag(const QPoint &pos)
Definition qtoolbar.cpp:143
void _q_updateIconSize(const QSize &sz)
Definition qtoolbar.cpp:88
QAction * toggleViewAction
Definition qtoolbar_p.h:61
The QToolBar class provides a movable panel that contains a set of controls.
Definition qtoolbar.h:23
QAction * addSeparator()
Adds a separator to the end of the toolbar.
Definition qtoolbar.cpp:745
QAction * insertSeparator(QAction *before)
Inserts a separator into the toolbar in front of the toolbar item associated with the before action.
Definition qtoolbar.cpp:759
Qt::Orientation orientation
orientation of the toolbar
Definition qtoolbar.h:30
QSize iconSize
size of icons in the toolbar.
Definition qtoolbar.h:31
~QToolBar()
Destroys the toolbar.
Definition qtoolbar.cpp:531
Qt::ToolButtonStyle toolButtonStyle
the style of toolbar buttons
Definition qtoolbar.h:33
QRect actionGeometry(QAction *action) const
Definition qtoolbar.cpp:816
void changeEvent(QEvent *event) override
\reimp
Definition qtoolbar.cpp:897
bool isMovable() const
Definition qtoolbar.cpp:557
void visibilityChanged(bool visible)
bool movable
whether the user can move the toolbar within the toolbar area, or between toolbar areas.
Definition qtoolbar.h:26
void setFloatable(bool floatable)
Definition qtoolbar.cpp:575
QToolBar(const QString &title, QWidget *parent=nullptr)
Constructs a QToolBar with the given parent.
Definition qtoolbar.cpp:521
void actionEvent(QActionEvent *event) override
\reimp
Definition qtoolbar.cpp:851
void setAllowedAreas(Qt::ToolBarAreas areas)
Definition qtoolbar.cpp:606
void orientationChanged(Qt::Orientation orientation)
This signal is emitted when the orientation of the toolbar changes.
QAction * insertWidget(QAction *before, QWidget *widget)
Inserts the given widget in front of the toolbar item associated with the before action.
Definition qtoolbar.cpp:801
void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
This signal is emitted when the tool button style is changed.
bool isFloating() const
Definition qtoolbar.cpp:589
QAction * actionAt(const QPoint &p) const
Returns the action at point p.
Definition qtoolbar.cpp:832
void clear()
Removes all actions from the toolbar.
Definition qtoolbar.cpp:733
QWidget * widgetForAction(QAction *action) const
void movableChanged(bool movable)
This signal is emitted when the toolbar becomes movable or fixed.
QAction * toggleViewAction() const
Returns a checkable action that can be used to show or hide this toolbar.
virtual void initStyleOption(QStyleOptionToolBar *option) const
bool floatable
whether the toolbar can be dragged and dropped as an independent window.
Definition qtoolbar.h:35
bool event(QEvent *event) override
\reimp
Definition qtoolbar.cpp:995
void allowedAreasChanged(Qt::ToolBarAreas allowedAreas)
This signal is emitted when the collection of allowed areas for the toolbar is changed.
void setIconSize(const QSize &iconSize)
Definition qtoolbar.cpp:668
void setMovable(bool movable)
Definition qtoolbar.cpp:547
void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
Definition qtoolbar.cpp:717
QAction * addWidget(QWidget *widget)
Adds the given widget to the toolbar as the toolbar's last item.
Definition qtoolbar.cpp:782
Qt::ToolBarAreas allowedAreas
areas where the toolbar may be placed
Definition qtoolbar.h:28
void paintEvent(QPaintEvent *event) override
\reimp
Definition qtoolbar.cpp:920
bool isFloatable() const
Definition qtoolbar.cpp:569
void iconSizeChanged(const QSize &iconSize)
This signal is emitted when the icon size is changed.
void setOrientation(Qt::Orientation orientation)
Definition qtoolbar.cpp:633
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3124
The QWidgetAction class extends QAction by an interface for inserting custom widgets into action base...
void setDefaultWidget(QWidget *w)
Sets widget to be the default widget.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
int metric(PaintDeviceMetric) const override
Internal implementation of the virtual QPaintDevice::metric() function.
QWidget * window() const
Returns the window for this widget, i.e.
Definition qwidget.cpp:4320
void setMinimumSize(const QSize &)
Definition qwidget.h:832
void setSizePolicy(QSizePolicy)
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition qwidget.h:877
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
QPalette palette
the widget's palette
Definition qwidget.h:132
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
QWidget * childAt(int x, int y) const
Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system.
Definition qwidget.h:798
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
void unsetCursor()
Definition qwidget.cpp:4990
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget's actions.
Definition qwidget.cpp:3214
void insertAction(QAction *before, QAction *action)
Inserts the action action to this widget's list of actions, before the action before.
Definition qwidget.cpp:3149
QWindow * windowHandle() const
If this is a native widget, return the associated QWindow.
Definition qwidget.cpp:2490
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9428
void setWindowTitle(const QString &)
Definition qwidget.cpp:6109
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8912
QStyle * style() const
Definition qwidget.cpp:2607
QString windowTitle
the window title (caption)
Definition qwidget.h:151
bool underMouse() const
Returns true if the widget is under the mouse cursor; otherwise returns false.
Definition qwidget.h:859
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition qwidget.h:811
void removeAction(QAction *action)
Removes the action action from this widget's list of actions.
Definition qwidget.cpp:3193
QPointF mapFromGlobal(const QPointF &) const
Translates the global screen coordinate pos to widget coordinates.
void setCursor(const QCursor &)
Definition qwidget.cpp:4967
\inmodule QtGui
Definition qwindow.h:63
QOpenGLWidget * widget
[1]
double e
opt iconSize
rect
[4]
QStyleOptionButton opt
T fromNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
@ LeftButton
Definition qnamespace.h:57
@ NoButton
Definition qnamespace.h:56
@ WA_Hover
Definition qnamespace.h:339
@ WA_X11NetWmWindowTypeToolBar
Definition qnamespace.h:387
@ TopToolBarArea
@ NoToolBarArea
@ ToolBarArea_Mask
Orientation
Definition qnamespace.h:97
@ Horizontal
Definition qnamespace.h:98
@ Vertical
Definition qnamespace.h:99
@ SizeAllCursor
@ IgnoreAction
@ Widget
Definition qnamespace.h:205
@ FramelessWindowHint
Definition qnamespace.h:224
@ Tool
Definition qnamespace.h:211
@ X11BypassWindowManagerHint
Definition qnamespace.h:223
ToolButtonStyle
#define Q_FALLTHROUGH()
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *window)
#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
GLboolean GLboolean GLboolean b
GLuint64 GLenum void * handle
GLfloat GLfloat GLfloat w
[0]
GLuint index
[2]
GLboolean r
[2]
GLbitfield flags
GLboolean enable
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLuint GLenum option
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
#define emit
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *window)
static bool waitForPopup(QToolBar *tb, QWidget *popup)
Definition qtoolbar.cpp:950
#define POPUP_TIMER_INTERVAL
Definition qtoolbar.cpp:43
QWidget * qobject_cast< QWidget * >(QObject *o)
Definition qwidget.h:786
#define enabled
QWidget * win
Definition settings.cpp:6
QString title
[35]
QGraphicsItem * item
aWidget window() -> setWindowTitle("New Window Title")
[2]
QMenu menu
[5]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent