Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 QT_CONFIG(draganddrop)
115 // If we are performing a platform drag the flag is not needed and we want to avoid recreating
116 // the platform window when it would be removed later
117 if (unplug && !QMainWindowLayout::needsPlatformDrag())
119#endif
120
121 q->setWindowFlags(flags);
122}
123
124void QToolBarPrivate::setWindowState(bool floating, bool unplug, const QRect &rect)
125{
126 Q_Q(QToolBar);
127 bool visible = !q->isHidden();
128 bool wasFloating = q->isFloating(); // ...is also currently using popup menus
129
130 updateWindowFlags(floating, unplug);
131
132 if (floating != wasFloating)
134
135 if (!rect.isNull())
136 q->setGeometry(rect);
137
138 if (visible)
139 q->show();
140
141 if (floating != wasFloating)
142 emit q->topLevelChanged(floating);
143}
144
146{
147 Q_Q(QToolBar);
148
149 if (state != nullptr)
150 return;
151
152 QMainWindow *win = qobject_cast<QMainWindow*>(parent);
153 Q_ASSERT(win != nullptr);
155 Q_ASSERT(layout != nullptr);
156 if (layout->pluggingWidget != nullptr) // the main window is animating a docking operation
157 return;
158
159 state = new DragState;
160 state->pressPos = pos;
161 state->dragging = false;
162 state->moving = false;
163 state->widgetItem = nullptr;
164
165 if (q->isRightToLeft())
166 state->pressPos = QPoint(q->width() - state->pressPos.x(), state->pressPos.y());
167}
168
170{
171 Q_Q(QToolBar);
172
173 Q_ASSERT(state != nullptr);
174
175 if ((moving && state->moving) || state->dragging)
176 return;
177
178 QMainWindow *win = qobject_cast<QMainWindow*>(parent);
179 Q_ASSERT(win != nullptr);
181 Q_ASSERT(layout != nullptr);
182
183#if QT_CONFIG(draganddrop)
184 const bool wasFloating = q->isFloating();
185#endif
186
187 if (!moving) {
189 Q_ASSERT(state->widgetItem != nullptr);
190 }
191 state->dragging = !moving;
192 state->moving = moving;
193
194#if QT_CONFIG(draganddrop)
195 if (QMainWindowLayout::needsPlatformDrag() && state->dragging) {
196 auto result = layout->performPlatformWidgetDrag(state->widgetItem, state->pressPos);
197 if (result == Qt::IgnoreAction && !wasFloating) {
198 layout->revert(state->widgetItem);
199 delete state;
200 state = nullptr;
201 } else {
202 endDrag();
203 }
204 }
205#endif
206}
207
209{
210 Q_Q(QToolBar);
211 Q_ASSERT(state != nullptr);
212
213 q->releaseMouse();
214
215 if (state->dragging) {
216 QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
217 Q_ASSERT(layout != nullptr);
218
219 if (!layout->plug(state->widgetItem)) {
220 if (q->isFloatable()) {
221 layout->restore();
222 setWindowState(true); // gets rid of the X11BypassWindowManager window flag
223 // and activates the resizer
224 q->activateWindow();
225 } else {
226 layout->revert(state->widgetItem);
227 }
228 }
229 }
230
231 delete state;
232 state = nullptr;
233}
234
236{
237 Q_Q(QToolBar);
238 QStyleOptionToolBar opt;
239 q->initStyleOption(&opt);
240 if (q->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, q).contains(event->position().toPoint()) == false) {
241#ifdef Q_OS_MACOS
242 // When using the unified toolbar on OS X, the user can click and
243 // drag between toolbar contents to move the window. Make this work by
244 // implementing the standard mouse-dragging code and then call
245 // window->move() in mouseMoveEvent below.
246 if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parent)) {
247 if (mainWindow->toolBarArea(q) == Qt::TopToolBarArea
248 && mainWindow->unifiedTitleAndToolBarOnMac()
249 && q->childAt(event->pos()) == 0) {
250 macWindowDragging = true;
251 macWindowDragPressPosition = event->pos();
252 return true;
253 }
254 }
255#endif
256 return false;
257 }
258
259 if (event->button() != Qt::LeftButton)
260 return true;
261
262 if (!layout->movable())
263 return true;
264
265 initDrag(event->position().toPoint());
266 return true;
267}
268
270{
271#if QT_CONFIG(draganddrop)
272 // if we are peforming a platform drag ignore the release here and end the drag when the actual
273 // drag ends.
274 if (QMainWindowLayout::needsPlatformDrag())
275 return false;
276#endif
277
278 if (state != nullptr) {
279 endDrag();
280 return true;
281 } else {
282#ifdef Q_OS_MACOS
283 if (!macWindowDragging)
284 return false;
285 macWindowDragging = false;
286 macWindowDragPressPosition = QPoint();
287 return true;
288#endif
289 return false;
290 }
291}
292
294{
295 Q_Q(QToolBar);
296
297 if (!state) {
298#ifdef Q_OS_MACOS
299 if (!macWindowDragging)
300 return false;
301 QWidget *w = q->window();
302 const QPoint delta = event->pos() - macWindowDragPressPosition;
303 w->move(w->pos() + delta);
304 return true;
305#endif
306 return false;
307 }
308
309 QMainWindow *win = qobject_cast<QMainWindow*>(parent);
310 if (win == nullptr)
311 return true;
312
314 Q_ASSERT(layout != nullptr);
315
316 if (layout->pluggingWidget == nullptr
317 && (event->position().toPoint() - state->pressPos).manhattanLength() > QApplication::startDragDistance()) {
318 const bool wasDragging = state->dragging;
319 const bool moving = !q->isWindow() && (orientation == Qt::Vertical ?
320 event->position().toPoint().x() >= 0 && event->position().toPoint().x() < q->width() :
321 event->position().toPoint().y() >= 0 && event->position().toPoint().y() < q->height());
322
323 startDrag(moving);
324 if (!moving && !wasDragging)
325 q->grabMouse();
326 }
327
328 if (!state) {
329 q->releaseMouse();
330 return true;
331 }
332
333 if (state->dragging) {
334 QPoint pos = event->globalPosition().toPoint();
335 // if we are right-to-left, we move so as to keep the right edge the same distance
336 // from the mouse
337 if (q->isLeftToRight())
338 pos -= state->pressPos;
339 else
340 pos += QPoint(state->pressPos.x() - q->width(), -state->pressPos.y());
341
342 q->move(pos);
343 layout->hover(state->widgetItem, event->globalPosition().toPoint());
344 } else if (state->moving) {
345
346 const QPoint rtl(q->width() - state->pressPos.x(), state->pressPos.y()); //for RTL
347 const QPoint globalPressPos = q->mapToGlobal(q->isRightToLeft() ? rtl : state->pressPos);
348 int pos = 0;
349
350 const QWindow *handle = q->window() ? q->window()->windowHandle() : nullptr;
351 const QPoint delta = handle
352 ? QHighDpi::fromNativePixels(event->globalPosition(), handle).toPoint()
353 - QHighDpi::fromNativePixels(globalPressPos, handle)
354 : event->globalPosition().toPoint() - globalPressPos;
355
356 if (orientation == Qt::Vertical) {
357 pos = q->y() + delta.y();
358 } else {
359 if (q->isRightToLeft()) {
360 pos = win->width() - q->width() - q->x() - delta.x();
361 } else {
362 pos = q->x() + delta.x();
363 }
364 }
365
366 layout->moveToolBar(q, pos);
367 }
368 return true;
369}
370
372{
373 Q_Q(QToolBar);
374 QRect r = _r;
375 r.moveTopLeft(q->mapToGlobal(QPoint(0, 0)));
376 setWindowState(true, true, r);
377 layout->setExpanded(false);
378}
379
381{
382 setWindowState(false, false, r);
383}
384
385/******************************************************************************
386** QToolBar
387*/
388
517 : QWidget(*new QToolBarPrivate, parent, { })
518{
519 Q_D(QToolBar);
520 d->init();
521}
522
532 : QToolBar(parent)
533{
535}
536
537
544
557void QToolBar::setMovable(bool movable)
558{
559 Q_D(QToolBar);
560 if (!movable == !d->movable)
561 return;
562 d->movable = movable;
563 d->layout->invalidate();
564 emit movableChanged(d->movable);
565}
566
568{
569 Q_D(const QToolBar);
570 return d->movable;
571}
572
580{
581 Q_D(const QToolBar);
582 return d->floatable;
583}
584
585void QToolBar::setFloatable(bool floatable)
586{
587 Q_D(QToolBar);
588 d->floatable = floatable;
589}
590
600{
601 return isWindow();
602}
603
616void QToolBar::setAllowedAreas(Qt::ToolBarAreas areas)
617{
618 Q_D(QToolBar);
619 areas &= Qt::ToolBarArea_Mask;
620 if (areas == d->allowedAreas)
621 return;
622 d->allowedAreas = areas;
623 emit allowedAreasChanged(d->allowedAreas);
624}
625
626Qt::ToolBarAreas QToolBar::allowedAreas() const
627{
628 Q_D(const QToolBar);
629 return d->allowedAreas;
630}
631
644{
645 Q_D(QToolBar);
646 if (orientation == d->orientation)
647 return;
648
649 d->orientation = orientation;
650
653 else
655
656 d->layout->invalidate();
657 d->layout->activate();
658
659 emit orientationChanged(d->orientation);
660}
661
663{ Q_D(const QToolBar); return d->orientation; }
664
676{ Q_D(const QToolBar); return d->iconSize; }
677
679{
680 Q_D(QToolBar);
681 QSize sz = iconSize;
682 if (!sz.isValid()) {
683 QMainWindow *mw = qobject_cast<QMainWindow *>(parentWidget());
684 if (mw && mw->layout()) {
685 QLayout *layout = mw->layout();
686 int i = 0;
687 QLayoutItem *item = nullptr;
688 do {
689 item = layout->itemAt(i++);
690 if (item && (item->widget() == this))
691 sz = mw->iconSize();
692 } while (!sz.isValid() && item != nullptr);
693 }
694 }
695 if (!sz.isValid()) {
696 const int metric = style()->pixelMetric(QStyle::PM_ToolBarIconSize, nullptr, this);
697 sz = QSize(metric, metric);
698 }
699 if (d->iconSize != sz) {
700 d->iconSize = sz;
701 setMinimumSize(0, 0);
702 emit iconSizeChanged(d->iconSize);
703 }
704 d->explicitIconSize = iconSize.isValid();
705
706 d->layout->invalidate();
707}
708
725{ Q_D(const QToolBar); return d->toolButtonStyle; }
726
728{
729 Q_D(QToolBar);
730 d->explicitToolButtonStyle = true;
731 if (d->toolButtonStyle == toolButtonStyle)
732 return;
733 d->toolButtonStyle = toolButtonStyle;
734 setMinimumSize(0, 0);
735 emit toolButtonStyleChanged(d->toolButtonStyle);
736}
737
744{
745 QList<QAction *> actions = this->actions();
746 for(int i = 0; i < actions.size(); i++)
748}
749
756{
757 QAction *action = new QAction(this);
758 action->setSeparator(true);
759 addAction(action);
760 return action;
761}
762
770{
771 QAction *action = new QAction(this);
772 action->setSeparator(true);
773 insertAction(before, action);
774 return action;
775}
776
793{
794 QWidgetAction *action = new QWidgetAction(this);
795 action->setDefaultWidget(widget);
796 action->d_func()->autoCreated = true;
797 addAction(action);
798 return action;
799}
800
812{
813 QWidgetAction *action = new QWidgetAction(this);
814 action->setDefaultWidget(widget);
815 action->d_func()->autoCreated = true;
816 insertAction(before, action);
817 return action;
818}
819
827{
828 Q_D(const QToolBar);
829
830 int index = d->layout->indexOf(action);
831 if (index == -1)
832 return QRect();
833 return d->layout->itemAt(index)->widget()->geometry();
834}
835
843{
844 Q_D(const QToolBar);
846 int index = d->layout->indexOf(widget);
847 if (index == -1)
848 return nullptr;
849 QLayoutItem *item = d->layout->itemAt(index);
850 return static_cast<QToolBarItem*>(item)->action;
851}
852
862{
863 Q_D(QToolBar);
864 auto action = static_cast<QAction *>(event->action());
865 QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(action);
866
867 switch (event->type()) {
868 case QEvent::ActionAdded: {
869 Q_ASSERT_X(widgetAction == nullptr || d->layout->indexOf(widgetAction) == -1,
870 "QToolBar", "widgets cannot be inserted multiple times");
871
872 // reparent the action to this toolbar if it has been created
873 // using the addAction(text) etc. convenience functions, to
874 // preserve Qt 4.1.x behavior. The widget is already
875 // reparented to us due to the createWidget call inside
876 // createItem()
877 if (widgetAction != nullptr && widgetAction->d_func()->autoCreated)
878 widgetAction->setParent(this);
879
880 int index = d->layout->count();
881 if (event->before()) {
882 index = d->layout->indexOf(event->before());
883 Q_ASSERT_X(index != -1, "QToolBar::insertAction", "internal error");
884 }
885 d->layout->insertAction(index, action);
886 break;
887 }
888
890 d->layout->invalidate();
891 break;
892
894 int index = d->layout->indexOf(action);
895 if (index != -1) {
896 delete d->layout->takeAt(index);
897 }
898 break;
899 }
900
901 default:
902 Q_ASSERT_X(false, "QToolBar::actionEvent", "internal error");
903 }
904}
905
908{
909 Q_D(QToolBar);
910 switch (event->type()) {
912 d->toggleViewAction->setText(windowTitle());
913 break;
915 d->layout->invalidate();
916 if (!d->explicitIconSize)
918 d->layout->updateMarginAndSpacing();
919 break;
921 d->layout->invalidate();
922 break;
923 default:
924 break;
925 }
927}
928
931{
932 Q_D(QToolBar);
933
934 QPainter p(this);
935 QStyle *style = this->style();
936 QStyleOptionToolBar opt;
938
939 if (d->layout->expanded || d->layout->animating || isWindow()) {
940 //if the toolbar is expended, we need to fill the background with the window color
941 //because some styles may expects that.
942 p.fillRect(opt.rect, palette().window());
945 } else {
947 }
948
950 if (opt.rect.isValid())
952}
953
954/*
955 Checks if an expanded toolbar has to wait for this popup to close before
956 the toolbar collapses. This is true if
957 1) the popup has the toolbar in its parent chain,
958 2) the popup is a menu whose menuAction is somewhere in the toolbar.
959*/
960static bool waitForPopup(QToolBar *tb, QWidget *popup)
961{
962 if (popup == nullptr || popup->isHidden())
963 return false;
964
965 QWidget *w = popup;
966 while (w != nullptr) {
967 if (w == tb)
968 return true;
969 w = w->parentWidget();
970 }
971
972 QMenu *menu = qobject_cast<QMenu*>(popup);
973 if (menu == nullptr)
974 return false;
975
976 const QAction *action = menu->menuAction();
977 for (auto object : action->associatedObjects()) {
978 if (QWidget *widget = qobject_cast<QWidget*>(object)) {
979 if (waitForPopup(tb, widget))
980 return true;
981 }
982 }
983
984 return false;
985}
986
987#ifdef Q_OS_MACOS
988static void enableMacToolBar(QToolBar *toolbar, bool enable)
989{
991 if (!nativeInterface)
992 return;
994 nativeInterface->nativeResourceFunctionForIntegration("setContentBorderAreaEnabled");
995 if (!function)
996 return; // Not Cocoa platform plugin.
997
998 typedef void (*SetContentBorderAreaEnabledFunction)(QWindow *window, void *identifier, bool enabled);
999 (reinterpret_cast<SetContentBorderAreaEnabledFunction>(function))(toolbar->window()->windowHandle(), toolbar, enable);
1000}
1001#endif
1002
1003
1006{
1007 Q_D(QToolBar);
1008
1009 switch (event->type()) {
1010 case QEvent::Timer:
1011 if (d->waitForPopupTimer.timerId() == static_cast<QTimerEvent*>(event)->timerId()) {
1013 if (!waitForPopup(this, w)) {
1014 d->waitForPopupTimer.stop();
1015 if (!this->underMouse())
1016 d->layout->setExpanded(false);
1017 }
1018 }
1019 break;
1020 case QEvent::Hide:
1021 if (!isHidden())
1022 break;
1023 Q_FALLTHROUGH();
1024 case QEvent::Show:
1025 d->toggleViewAction->setChecked(event->type() == QEvent::Show);
1026#ifdef Q_OS_MACOS
1027 enableMacToolBar(this, event->type() == QEvent::Show);
1028#endif
1030 break;
1032 d->layout->checkUsePopupMenu();
1033 break;
1034
1036 if (d->mousePressEvent(static_cast<QMouseEvent*>(event)))
1037 return true;
1038 break;
1039 }
1041 if (d->mouseReleaseEvent(static_cast<QMouseEvent*>(event)))
1042 return true;
1043 break;
1044 case QEvent::HoverEnter:
1045 case QEvent::HoverLeave:
1046 // there's nothing special to do here and we don't want to update the whole widget
1047 return true;
1048 case QEvent::HoverMove: {
1049#ifndef QT_NO_CURSOR
1050 QHoverEvent *e = static_cast<QHoverEvent*>(event);
1051 QStyleOptionToolBar opt;
1053 if (style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, this).contains(e->position().toPoint()))
1055 else
1056 unsetCursor();
1057#endif
1058 break;
1059 }
1060 case QEvent::MouseMove:
1061 if (d->mouseMoveEvent(static_cast<QMouseEvent*>(event)))
1062 return true;
1063 break;
1064 case QEvent::Leave:
1065 if (d->state != nullptr && d->state->dragging) {
1066#ifdef Q_OS_WIN
1067 // This is a workaround for losing the mouse on Vista.
1071 d->mouseMoveEvent(&fake);
1072#endif
1073 } else {
1074 if (!d->layout->expanded)
1075 break;
1076
1078 if (waitForPopup(this, w)) {
1079 d->waitForPopupTimer.start(POPUP_TIMER_INTERVAL, this);
1080 break;
1081 }
1082
1083 d->waitForPopupTimer.stop();
1084 d->layout->setExpanded(false);
1085 break;
1086 }
1087 break;
1088 default:
1089 break;
1090 }
1091 return QWidget::event(event);
1092}
1093
1103{ Q_D(const QToolBar); return d->toggleViewAction; }
1104
1113{
1114 Q_D(const QToolBar);
1115
1116 int index = d->layout->indexOf(action);
1117 if (index == -1)
1118 return nullptr;
1119
1120 return d->layout->itemAt(index)->widget();
1121}
1122
1124
1128void QToolBar::initStyleOption(QStyleOptionToolBar *option) const
1129{
1130 Q_D(const QToolBar);
1131
1132 if (!option)
1133 return;
1134
1135 option->initFrom(this);
1136 if (orientation() == Qt::Horizontal)
1138 option->lineWidth = style()->pixelMetric(QStyle::PM_ToolBarFrameWidth, nullptr, this);
1139 option->features = d->layout->movable()
1140 ? QStyleOptionToolBar::Movable
1141 : QStyleOptionToolBar::None;
1142 // if the tool bar is not in a QMainWindow, this will make the painting right
1143 option->toolBarArea = Qt::NoToolBarArea;
1144
1145 // Add more styleoptions if the toolbar has been added to a mainwindow.
1146 QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
1147
1148 if (!mainWindow)
1149 return;
1150
1152 Q_ASSERT_X(layout != nullptr, "QToolBar::initStyleOption()",
1153 "QMainWindow->layout() != QMainWindowLayout");
1154
1155 layout->getStyleOptionInfo(option, const_cast<QToolBar *>(this));
1156}
1157
1159
1160#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:304
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:246
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.
QLayout * layout() override
\reimp
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
The QMainWindow class provides a main application window.
Definition qmainwindow.h:25
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:1069
\inmodule QtGui
Definition qevent.h:196
QObject * parent
Definition qobject.h:73
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
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)
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
\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:304
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:170
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:119
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:127
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
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:672
@ 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:492
@ PM_ToolBarFrameWidth
Definition qstyle.h:483
@ 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:366
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition qcoreevent.h:370
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:380
void updateWindowFlags(bool floating, bool unplug=false)
Definition qtoolbar.cpp:107
void startDrag(bool moving=false)
Definition qtoolbar.cpp:169
bool mousePressEvent(QMouseEvent *e)
Definition qtoolbar.cpp:235
void unplug(const QRect &r)
Definition qtoolbar.cpp:371
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:124
bool mouseMoveEvent(QMouseEvent *e)
Definition qtoolbar.cpp:293
bool explicitIconSize
Definition qtoolbar_p.h:52
void _q_updateToolButtonStyle(Qt::ToolButtonStyle style)
Definition qtoolbar.cpp:98
bool mouseReleaseEvent(QMouseEvent *e)
Definition qtoolbar.cpp:269
DragState * state
Definition qtoolbar_p.h:71
void initDrag(const QPoint &pos)
Definition qtoolbar.cpp:145
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:755
QAction * insertSeparator(QAction *before)
Inserts a separator into the toolbar in front of the toolbar item associated with the before action.
Definition qtoolbar.cpp:769
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:541
Qt::ToolButtonStyle toolButtonStyle
the style of toolbar buttons
Definition qtoolbar.h:33
QRect actionGeometry(QAction *action) const
Definition qtoolbar.cpp:826
void changeEvent(QEvent *event) override
\reimp
Definition qtoolbar.cpp:907
bool isMovable() const
Definition qtoolbar.cpp:567
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:585
QToolBar(const QString &title, QWidget *parent=nullptr)
Constructs a QToolBar with the given parent.
Definition qtoolbar.cpp:531
void actionEvent(QActionEvent *event) override
\reimp
Definition qtoolbar.cpp:861
void setAllowedAreas(Qt::ToolBarAreas areas)
Definition qtoolbar.cpp:616
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:811
void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
This signal is emitted when the tool button style is changed.
bool isFloating() const
Definition qtoolbar.cpp:599
QAction * actionAt(const QPoint &p) const
Returns the action at point p.
Definition qtoolbar.cpp:842
void clear()
Removes all actions from the toolbar.
Definition qtoolbar.cpp:743
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
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:678
void setMovable(bool movable)
Definition qtoolbar.cpp:557
void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
Definition qtoolbar.cpp:727
QAction * addWidget(QWidget *widget)
Adds the given widget to the toolbar as the toolbar's last item.
Definition qtoolbar.cpp:792
Qt::ToolBarAreas allowedAreas
areas where the toolbar may be placed
Definition qtoolbar.h:28
void paintEvent(QPaintEvent *event) override
\reimp
Definition qtoolbar.cpp:930
bool isFloatable() const
Definition qtoolbar.cpp:579
void iconSizeChanged(const QSize &iconSize)
This signal is emitted when the icon size is changed.
void setOrientation(Qt::Orientation orientation)
Definition qtoolbar.cpp:643
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
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:4313
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:4983
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget's actions.
Definition qwidget.cpp:3207
void insertAction(QAction *before, QAction *action)
Inserts the action action to this widget's list of actions, before the action before.
Definition qwidget.cpp:3142
QWindow * windowHandle() const
If this is a native widget, return the associated QWindow.
Definition qwidget.cpp:2483
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9382
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
QStyle * style() const
Definition qwidget.cpp:2600
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:3186
QPointF mapFromGlobal(const QPointF &) const
Translates the global screen coordinate pos to widget coordinates.
void setCursor(const QCursor &)
Definition qwidget.cpp:4960
\inmodule QtGui
Definition qwindow.h:63
QOpenGLWidget * widget
[1]
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:58
@ NoButton
Definition qnamespace.h:57
@ WA_Hover
Definition qnamespace.h:340
@ WA_X11NetWmWindowTypeToolBar
Definition qnamespace.h:388
@ TopToolBarArea
@ NoToolBarArea
@ ToolBarArea_Mask
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
@ SizeAllCursor
@ IgnoreAction
@ Widget
Definition qnamespace.h:206
@ FramelessWindowHint
Definition qnamespace.h:225
@ Tool
Definition qnamespace.h:212
@ X11BypassWindowManagerHint
Definition qnamespace.h:224
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:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
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:960
#define POPUP_TIMER_INTERVAL
Definition qtoolbar.cpp:43
#define enabled
QWidget * win
Definition settings.cpp:6
QString title
[35]
QGraphicsItem * item
aWidget window() -> setWindowTitle("New Window Title")
[2]
QMenu menu
[5]