Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qmainwindow.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// Qt-Security score:significant reason:default
4
5#include "qmainwindow.h"
7
8#if QT_CONFIG(dockwidget)
9#include "qdockwidget.h"
10#endif
11#if QT_CONFIG(toolbar)
12#include "qtoolbar.h"
13#endif
14
15#include <qapplication.h>
16#include <qmenu.h>
17#if QT_CONFIG(menubar)
18#include <qmenubar.h>
19#endif
20#if QT_CONFIG(statusbar)
21#include <qstatusbar.h>
22#endif
23#include <qevent.h>
24#include <qstyle.h>
25#include <qdebug.h>
26#include <qpainter.h>
27#include <qmimedata.h>
28
29#include <private/qwidget_p.h>
30#if QT_CONFIG(toolbar)
31#include "qtoolbar_p.h"
32#endif
34#include <QtGui/qpa/qplatformwindow.h>
35#include <QtGui/qpa/qplatformwindow_p.h>
36
38
39using namespace Qt::StringLiterals;
40
42{
43 Q_DECLARE_PUBLIC(QMainWindow)
44public:
47#ifdef Q_OS_MACOS
48 , useUnifiedToolBar(false)
49#endif
50 { }
55#ifdef Q_OS_MACOS
57#endif
58 void init();
59
60 static inline QMainWindowLayout *mainWindowLayout(const QMainWindow *mainWindow)
61 {
62 return mainWindow ? mainWindow->d_func()->layout.data() : static_cast<QMainWindowLayout *>(nullptr);
63 }
64};
65
66QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *mainWindow)
67{
68 return QMainWindowPrivate::mainWindowLayout(mainWindow);
69}
70
72{
73 Q_Q(QMainWindow);
74
75 layout = new QMainWindowLayout(q, nullptr);
76
77 const int metric = q->style()->pixelMetric(QStyle::PM_ToolBarIconSize, nullptr, q);
78 iconSize = QSize(metric, metric);
79 q->setAttribute(Qt::WA_Hover);
80 q->setAcceptDrops(true);
81}
82
83/*
84 The Main Window:
85
86 +----------------------------------------------------------+
87 | Menu Bar |
88 +----------------------------------------------------------+
89 | Tool Bar Area |
90 | +--------------------------------------------------+ |
91 | | Dock Window Area | |
92 | | +------------------------------------------+ | |
93 | | | | | |
94 | | | Central Widget | | |
95 | | | | | |
96 | | | | | |
97 | | | | | |
98 | | | | | |
99 | | | | | |
100 | | | | | |
101 | | | | | |
102 | | | | | |
103 | | | | | |
104 | | | | | |
105 | | +------------------------------------------+ | |
106 | | | |
107 | +--------------------------------------------------+ |
108 | |
109 +----------------------------------------------------------+
110 | Status Bar |
111 +----------------------------------------------------------+
112
113*/
114
115/*!
116 \class QMainWindow
117 \brief The QMainWindow class provides a main application
118 window.
119 \ingroup mainwindow-classes
120 \inmodule QtWidgets
121
122 \section1 Qt Main Window Framework
123
124 A main window provides a framework for building an
125 application's user interface. Qt has QMainWindow and its \l{Main
126 Window and Related Classes}{related classes} for main window
127 management. QMainWindow has its own layout to which you can add
128 \l{QToolBar}s, \l{QDockWidget}s, a
129 QMenuBar, and a QStatusBar. The layout has a center area that can
130 be occupied by any kind of widget. You can see an image of the
131 layout below.
132
133 \image mainwindowlayout.png
134 {Diagram of main window and the position of its components}
135
136 \section1 Creating Main Window Components
137
138 A central widget will typically be a standard Qt widget such
139 as a QTextEdit or a QGraphicsView. Custom widgets can also be
140 used for advanced applications. You set the central widget with \c
141 setCentralWidget().
142
143 Main windows have either a single (SDI) or multiple (MDI)
144 document interface. You create MDI applications in Qt by using a
145 QMdiArea as the central widget.
146
147 We will now examine each of the other widgets that can be
148 added to a main window. We give examples on how to create and add
149 them.
150
151 \section2 Creating Menus
152
153 Qt implements menus in QMenu and QMainWindow keeps them in a
154 QMenuBar. \l{QAction}{QAction}s are added to the menus, which
155 display them as menu items.
156
157 You can add new menus to the main window's menu bar by calling
158 \c menuBar(), which returns the QMenuBar for the window, and then
159 add a menu with QMenuBar::addMenu().
160
161 QMainWindow comes with a default menu bar, but you can also
162 set one yourself with \c setMenuBar(). If you wish to implement a
163 custom menu bar (i.e., not use the QMenuBar widget), you can set it
164 with \c setMenuWidget().
165
166 An example of how to create menus follows:
167
168 \snippet code/src_widgets_widgets_qmainwindow.cpp 0
169
170 The \c createPopupMenu() function creates popup menus when the
171 main window receives context menu events. The default
172 implementation generates a menu with the checkable actions from
173 the dock widgets and toolbars. You can reimplement \c
174 createPopupMenu() for a custom menu.
175
176 \section2 Creating Toolbars
177
178 Toolbars are implemented in the QToolBar class. You add a
179 toolbar to a main window with \c addToolBar().
180
181 You control the initial position of toolbars by assigning them
182 to a specific Qt::ToolBarArea. You can split an area by inserting
183 a toolbar break - think of this as a line break in text editing -
184 with \c addToolBarBreak() or \c insertToolBarBreak(). You can also
185 restrict placement by the user with QToolBar::setAllowedAreas()
186 and QToolBar::setMovable().
187
188 The size of toolbar icons can be retrieved with \c iconSize().
189 The sizes are platform dependent; you can set a fixed size with \c
190 setIconSize(). You can alter the appearance of all tool buttons in
191 the toolbars with \c setToolButtonStyle().
192
193 An example of toolbar creation follows:
194
195 \snippet code/src_widgets_widgets_qmainwindow.cpp 1
196
197 \section2 Creating Dock Widgets
198
199 Dock widgets are implemented in the QDockWidget class. A dock
200 widget is a window that can be docked into the main window. You
201 add dock widgets to a main window with \c addDockWidget().
202
203 There are four dock widget areas as given by the
204 Qt::DockWidgetArea enum: left, right, top, and bottom. You can
205 specify which dock widget area that should occupy the corners
206 where the areas overlap with \c setCorner(). By default
207 each area can only contain one row (vertical or horizontal) of
208 dock widgets, but if you enable nesting with \c
209 setDockNestingEnabled(), dock widgets can be added in either
210 direction.
211
212 Two dock widgets may also be stacked on top of each other. A
213 QTabBar is then used to select which of the widgets should be
214 displayed.
215
216 We give an example of how to create and add dock widgets to a
217 main window:
218
219 \snippet mainwindowsnippet.cpp 0
220
221 \section2 The Status Bar
222
223 You can set a status bar with \c setStatusBar(), but one is
224 created the first time \c statusBar() (which returns the main
225 window's status bar) is called. See QStatusBar for information on
226 how to use it.
227
228 \section1 Storing State
229
230 QMainWindow can store the state of its layout with \c
231 saveState(); it can later be retrieved with \c restoreState(). It
232 is the position and size (relative to the size of the main window)
233 of the toolbars and dock widgets that are stored.
234
235 \sa QMenuBar, QToolBar, QStatusBar, QDockWidget, {Menus Example}
236*/
237
238/*!
239 \fn void QMainWindow::iconSizeChanged(const QSize &iconSize)
240
241 This signal is emitted when the size of the icons used in the
242 window is changed. The new icon size is passed in \a iconSize.
243
244 You can connect this signal to other components to help maintain
245 a consistent appearance for your application.
246
247 \sa setIconSize()
248*/
249
250/*!
251 \fn void QMainWindow::toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
252
253 This signal is emitted when the style used for tool buttons in the
254 window is changed. The new style is passed in \a toolButtonStyle.
255
256 You can connect this signal to other components to help maintain
257 a consistent appearance for your application.
258
259 \sa setToolButtonStyle()
260*/
261
262#if QT_CONFIG(dockwidget)
263/*!
264 \fn void QMainWindow::tabifiedDockWidgetActivated(QDockWidget *dockWidget)
265
266 This signal is emitted when the tabified dock widget is activated by
267 selecting the tab. The activated dock widget is passed in \a dockWidget.
268
269 \since 5.8
270 \sa tabifyDockWidget(), tabifiedDockWidgets()
271*/
272#endif
273
274/*!
275 Constructs a QMainWindow with the given \a parent and the specified
276 widget \a flags.
277
278 QMainWindow sets the Qt::Window flag itself, and will hence
279 always be created as a top-level widget.
280 */
281QMainWindow::QMainWindow(QWidget *parent, Qt::WindowFlags flags)
282 : QWidget(*(new QMainWindowPrivate()), parent, flags | Qt::Window)
283{
284 d_func()->init();
285}
286
287
288/*!
289 Destroys the main window.
290 */
291QMainWindow::~QMainWindow()
292{ }
293
294/*! \property QMainWindow::iconSize
295 \brief size of toolbar icons in this mainwindow.
296
297 The default is the default tool bar icon size of the GUI style.
298 Note that the icons used must be at least of this size as the
299 icons are only scaled down.
300*/
301
302/*!
303 \property QMainWindow::dockOptions
304 \brief the docking behavior of QMainWindow
305 \since 4.3
306
307 The default value is AnimatedDocks | AllowTabbedDocks.
308*/
309
310/*!
311 \enum QMainWindow::DockOption
312 \since 4.3
313
314 This enum contains flags that specify the docking behavior of QMainWindow.
315
316 \value AnimatedDocks Identical to the \l animated property.
317
318 \value AllowNestedDocks Identical to the \l dockNestingEnabled property.
319
320 \value AllowTabbedDocks The user can drop one dock widget "on top" of
321 another. The two widgets are stacked and a tab
322 bar appears for selecting which one is visible.
323
324 \value ForceTabbedDocks Each dock area contains a single stack of tabbed
325 dock widgets. In other words, dock widgets cannot
326 be placed next to each other in a dock area. If
327 this option is set, AllowNestedDocks has no effect.
328
329 \value VerticalTabs The two vertical dock areas on the sides of the
330 main window show their tabs vertically. If this
331 option is not set, all dock areas show their tabs
332 at the bottom. Implies AllowTabbedDocks. See also
333 \l setTabPosition().
334
335 \value GroupedDragging When dragging the titlebar of a dock, all the tabs
336 that are tabbed with it are going to be dragged.
337 Implies AllowTabbedDocks. Does not work well if
338 some QDockWidgets have restrictions in which area
339 they are allowed. (This enum value was added in Qt
340 5.6.)
341
342 These options only control how dock widgets may be dropped in a QMainWindow.
343 They do not re-arrange the dock widgets to conform with the specified
344 options. For this reason they should be set before any dock widgets
345 are added to the main window. Exceptions to this are the AnimatedDocks and
346 VerticalTabs options, which may be set at any time.
347*/
348
349void QMainWindow::setDockOptions(DockOptions opt)
350{
351 Q_D(QMainWindow);
352 d->layout->setDockOptions(opt);
353}
354
355QMainWindow::DockOptions QMainWindow::dockOptions() const
356{
357 Q_D(const QMainWindow);
358 return d->layout->dockOptions;
359}
360
361QSize QMainWindow::iconSize() const
362{ return d_func()->iconSize; }
363
364void QMainWindow::setIconSize(const QSize &iconSize)
365{
366 Q_D(QMainWindow);
367 QSize sz = iconSize;
368 if (!sz.isValid()) {
369 const int metric = style()->pixelMetric(QStyle::PM_ToolBarIconSize, nullptr, this);
370 sz = QSize(metric, metric);
371 }
372 if (d->iconSize != sz) {
373 d->iconSize = sz;
374 emit iconSizeChanged(d->iconSize);
375 }
376 d->explicitIconSize = iconSize.isValid();
377}
378
379/*! \property QMainWindow::toolButtonStyle
380 \brief style of toolbar buttons in this mainwindow.
381
382 To have the style of toolbuttons follow the system settings, set this property to Qt::ToolButtonFollowStyle.
383 On Unix, the user settings from the desktop environment will be used.
384 On other platforms, Qt::ToolButtonFollowStyle means icon only.
385
386 The default is Qt::ToolButtonIconOnly.
387*/
388
389Qt::ToolButtonStyle QMainWindow::toolButtonStyle() const
390{ return d_func()->toolButtonStyle; }
391
392void QMainWindow::setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
393{
394 Q_D(QMainWindow);
395 if (d->toolButtonStyle == toolButtonStyle)
396 return;
397 d->toolButtonStyle = toolButtonStyle;
398 emit toolButtonStyleChanged(d->toolButtonStyle);
399}
400
401#if QT_CONFIG(menubar)
402/*!
403 Returns the menu bar for the main window. This function creates
404 and returns an empty menu bar if the menu bar does not exist.
405
406 If you want all windows in a Mac application to share one menu
407 bar, don't use this function to create it, because the menu bar
408 created here will have this QMainWindow as its parent. Instead,
409 you must create a menu bar that does not have a parent, which you
410 can then share among all the Mac windows. Create a parent-less
411 menu bar this way:
412
413 \snippet code/src_gui_widgets_qmenubar.cpp 1
414
415 \sa setMenuBar()
416*/
417QMenuBar *QMainWindow::menuBar() const
418{
419 QMenuBar *menuBar = qobject_cast<QMenuBar *>(layout()->menuBar());
420 if (!menuBar) {
421 QMainWindow *self = const_cast<QMainWindow *>(this);
422 menuBar = new QMenuBar(self);
423 self->setMenuBar(menuBar);
424 }
425 return menuBar;
426}
427
428/*!
429 Sets the menu bar for the main window to \a menuBar.
430
431 Note: QMainWindow takes ownership of the \a menuBar pointer and
432 deletes it at the appropriate time.
433
434 \sa menuBar()
435*/
436void QMainWindow::setMenuBar(QMenuBar *menuBar)
437{
438 QLayout *topLayout = layout();
439
440 if (QWidget *existingMenuBar = topLayout->menuBar(); existingMenuBar && existingMenuBar != menuBar) {
441 // Reparent corner widgets before we delete the old menu bar.
442 QMenuBar *oldMenuBar = qobject_cast<QMenuBar *>(existingMenuBar);
443 if (oldMenuBar && menuBar) {
444 // TopLeftCorner widget.
445 QWidget *cornerWidget = oldMenuBar->cornerWidget(Qt::TopLeftCorner);
446 if (cornerWidget)
447 menuBar->setCornerWidget(cornerWidget, Qt::TopLeftCorner);
448 // TopRightCorner widget.
449 cornerWidget = oldMenuBar->cornerWidget(Qt::TopRightCorner);
450 if (cornerWidget)
451 menuBar->setCornerWidget(cornerWidget, Qt::TopRightCorner);
452 }
453
454 existingMenuBar->hide();
455 existingMenuBar->setParent(nullptr);
456 existingMenuBar->deleteLater();
457 }
458 topLayout->setMenuBar(menuBar);
459}
460
461/*!
462 \since 4.2
463
464 Returns the menu bar for the main window. This function returns
465 null if a menu bar hasn't been constructed yet.
466*/
467QWidget *QMainWindow::menuWidget() const
468{
469 QWidget *menuBar = d_func()->layout->menuBar();
470 return menuBar;
471}
472
473/*!
474 \since 4.2
475
476 Sets the menu bar for the main window to \a menuBar.
477
478 QMainWindow takes ownership of the \a menuBar pointer and
479 deletes it at the appropriate time.
480*/
481void QMainWindow::setMenuWidget(QWidget *menuBar)
482{
483 Q_D(QMainWindow);
484 if (d->layout->menuBar() && d->layout->menuBar() != menuBar) {
485 d->layout->menuBar()->hide();
486 d->layout->menuBar()->deleteLater();
487 }
488 d->layout->setMenuBar(menuBar);
489}
490#endif // QT_CONFIG(menubar)
491
492#if QT_CONFIG(statusbar)
493/*!
494 Returns the status bar for the main window. This function creates
495 and returns an empty status bar if the status bar does not exist.
496
497 \sa setStatusBar()
498*/
499QStatusBar *QMainWindow::statusBar() const
500{
501 QStatusBar *statusbar = d_func()->layout->statusBar();
502 if (!statusbar) {
503 QMainWindow *self = const_cast<QMainWindow *>(this);
504 statusbar = new QStatusBar(self);
505 statusbar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
506 self->setStatusBar(statusbar);
507 }
508 return statusbar;
509}
510
511/*!
512 Sets the status bar for the main window to \a statusbar.
513
514 Setting the status bar to \nullptr will remove it from the main window.
515 Note that QMainWindow takes ownership of the \a statusbar pointer
516 and deletes it at the appropriate time.
517
518 \sa statusBar()
519*/
520void QMainWindow::setStatusBar(QStatusBar *statusbar)
521{
522 Q_D(QMainWindow);
523 if (d->layout->statusBar() && d->layout->statusBar() != statusbar) {
524 d->layout->statusBar()->hide();
525 d->layout->statusBar()->deleteLater();
526 }
527 d->layout->setStatusBar(statusbar);
528}
529#endif // QT_CONFIG(statusbar)
530
531/*!
532 Returns the central widget for the main window. This function
533 returns \nullptr if the central widget has not been set.
534
535 \sa setCentralWidget()
536*/
537QWidget *QMainWindow::centralWidget() const
538{ return d_func()->layout->centralWidget(); }
539
540/*!
541 Sets the given \a widget to be the main window's central widget.
542
543 Note: QMainWindow takes ownership of the \a widget pointer and
544 deletes it at the appropriate time.
545
546 \sa centralWidget()
547*/
548void QMainWindow::setCentralWidget(QWidget *widget)
549{
550 Q_D(QMainWindow);
551 if (d->layout->centralWidget() && d->layout->centralWidget() != widget) {
552 d->layout->centralWidget()->hide();
553 d->layout->centralWidget()->deleteLater();
554 }
555 d->layout->setCentralWidget(widget);
556}
557
558/*!
559 Removes the central widget from this main window.
560
561 The ownership of the removed widget is passed to the caller.
562
563 \since 5.2
564*/
565QWidget *QMainWindow::takeCentralWidget()
566{
567 Q_D(QMainWindow);
568 QWidget *oldcentralwidget = d->layout->centralWidget();
569 if (oldcentralwidget) {
570 oldcentralwidget->setParent(nullptr);
571 d->layout->setCentralWidget(nullptr);
572 }
573 return oldcentralwidget;
574}
575
576#if QT_CONFIG(dockwidget)
577/*!
578 Sets the given dock widget \a area to occupy the specified \a
579 corner.
580
581 \sa corner()
582*/
583void QMainWindow::setCorner(Qt::Corner corner, Qt::DockWidgetArea area)
584{
585 bool valid = false;
586 switch (corner) {
587 case Qt::TopLeftCorner:
588 valid = (area == Qt::TopDockWidgetArea || area == Qt::LeftDockWidgetArea);
589 break;
590 case Qt::TopRightCorner:
591 valid = (area == Qt::TopDockWidgetArea || area == Qt::RightDockWidgetArea);
592 break;
593 case Qt::BottomLeftCorner:
594 valid = (area == Qt::BottomDockWidgetArea || area == Qt::LeftDockWidgetArea);
595 break;
596 case Qt::BottomRightCorner:
597 valid = (area == Qt::BottomDockWidgetArea || area == Qt::RightDockWidgetArea);
598 break;
599 }
600 if (Q_UNLIKELY(!valid))
601 qWarning("QMainWindow::setCorner(): 'area' is not valid for 'corner'");
602 else
603 d_func()->layout->setCorner(corner, area);
604}
605
606/*!
607 Returns the dock widget area that occupies the specified \a
608 corner.
609
610 \sa setCorner()
611*/
612Qt::DockWidgetArea QMainWindow::corner(Qt::Corner corner) const
613{ return d_func()->layout->corner(corner); }
614#endif
615
616#if QT_CONFIG(toolbar)
617
618static bool checkToolBarArea(Qt::ToolBarArea area, const char *where)
619{
620 switch (area) {
621 case Qt::LeftToolBarArea:
622 case Qt::RightToolBarArea:
623 case Qt::TopToolBarArea:
624 case Qt::BottomToolBarArea:
625 return true;
626 default:
627 break;
628 }
629 qWarning("%s: invalid 'area' argument", where);
630 return false;
631}
632
633/*!
634 Adds a toolbar break to the given \a area after all the other
635 objects that are present.
636*/
637void QMainWindow::addToolBarBreak(Qt::ToolBarArea area)
638{
639 if (!checkToolBarArea(area, "QMainWindow::addToolBarBreak"))
640 return;
641 d_func()->layout->addToolBarBreak(area);
642}
643
644/*!
645 Inserts a toolbar break before the toolbar specified by \a before.
646*/
647void QMainWindow::insertToolBarBreak(QToolBar *before)
648{ d_func()->layout->insertToolBarBreak(before); }
649
650/*!
651 Removes a toolbar break previously inserted before the toolbar specified by \a before.
652*/
653
654void QMainWindow::removeToolBarBreak(QToolBar *before)
655{
656 Q_D(QMainWindow);
657 d->layout->removeToolBarBreak(before);
658}
659
660/*!
661 Adds the \a toolbar into the specified \a area in this main
662 window. The \a toolbar is placed at the end of the current tool
663 bar block (i.e. line). If the main window already manages \a toolbar
664 then it will only move the toolbar to \a area.
665
666 \sa insertToolBar(), addToolBarBreak(), insertToolBarBreak()
667*/
668void QMainWindow::addToolBar(Qt::ToolBarArea area, QToolBar *toolbar)
669{
670 if (!checkToolBarArea(area, "QMainWindow::addToolBar"))
671 return;
672
673 Q_D(QMainWindow);
674
675 disconnect(this, SIGNAL(iconSizeChanged(QSize)),
676 toolbar, SLOT(_q_updateIconSize(QSize)));
677 disconnect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
678 toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));
679
680 if (toolbar->d_func()->state && toolbar->d_func()->state->dragging) {
681 //removing a toolbar which is dragging will cause crash
682#if QT_CONFIG(dockwidget)
683 bool animated = isAnimated();
684 setAnimated(false);
685#endif
686 toolbar->d_func()->endDrag();
687#if QT_CONFIG(dockwidget)
688 setAnimated(animated);
689#endif
690 }
691
692 d->layout->removeToolBar(toolbar);
693
694 toolbar->d_func()->_q_updateIconSize(d->iconSize);
695 toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle);
696 connect(this, SIGNAL(iconSizeChanged(QSize)),
697 toolbar, SLOT(_q_updateIconSize(QSize)));
698 connect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
699 toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));
700
701 d->layout->addToolBar(area, toolbar);
702}
703
704/*! \overload
705 Equivalent of calling addToolBar(Qt::TopToolBarArea, \a toolbar)
706*/
707void QMainWindow::addToolBar(QToolBar *toolbar)
708{ addToolBar(Qt::TopToolBarArea, toolbar); }
709
710/*!
711 \overload
712
713 Creates a QToolBar object, setting its window title to \a title,
714 and inserts it into the top toolbar area.
715
716 \sa setWindowTitle()
717*/
718QToolBar *QMainWindow::addToolBar(const QString &title)
719{
720 QToolBar *toolBar = new QToolBar(this);
721 toolBar->setWindowTitle(title);
722 addToolBar(toolBar);
723 return toolBar;
724}
725
726/*!
727 Inserts the \a toolbar into the area occupied by the \a before toolbar
728 so that it appears before it. For example, in normal left-to-right
729 layout operation, this means that \a toolbar will appear to the left
730 of the toolbar specified by \a before in a horizontal toolbar area.
731
732 \sa insertToolBarBreak(), addToolBar(), addToolBarBreak()
733*/
734void QMainWindow::insertToolBar(QToolBar *before, QToolBar *toolbar)
735{
736 Q_D(QMainWindow);
737
738 d->layout->removeToolBar(toolbar);
739
740 toolbar->d_func()->_q_updateIconSize(d->iconSize);
741 toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle);
742 connect(this, SIGNAL(iconSizeChanged(QSize)),
743 toolbar, SLOT(_q_updateIconSize(QSize)));
744 connect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
745 toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));
746
747 d->layout->insertToolBar(before, toolbar);
748}
749
750/*!
751 Removes the \a toolbar from the main window layout and hides
752 it. Note that the \a toolbar is \e not deleted.
753*/
754void QMainWindow::removeToolBar(QToolBar *toolbar)
755{
756 if (toolbar) {
757 d_func()->layout->removeToolBar(toolbar);
758 toolbar->hide();
759 }
760}
761
762/*!
763 Returns the Qt::ToolBarArea for \a toolbar. If \a toolbar has not
764 been added to the main window, this function returns \c
765 Qt::NoToolBarArea.
766
767 \sa addToolBar(), addToolBarBreak(), Qt::ToolBarArea
768*/
769Qt::ToolBarArea QMainWindow::toolBarArea(const QToolBar *toolbar) const
770{ return d_func()->layout->toolBarArea(toolbar); }
771
772/*!
773
774 Returns whether there is a toolbar
775 break before the \a toolbar.
776
777 \sa addToolBarBreak(), insertToolBarBreak()
778*/
779bool QMainWindow::toolBarBreak(QToolBar *toolbar) const
780{
781 return d_func()->layout->toolBarBreak(toolbar);
782}
783
784#endif // QT_CONFIG(toolbar)
785
786#if QT_CONFIG(dockwidget)
787
788/*! \property QMainWindow::animated
789 \brief whether manipulating dock widgets and tool bars is animated
790 \since 4.2
791
792 When a dock widget or tool bar is dragged over the
793 main window, the main window adjusts its contents
794 to indicate where the dock widget or tool bar will
795 be docked if it is dropped. Setting this property
796 causes QMainWindow to move its contents in a smooth
797 animation. Clearing this property causes the contents
798 to snap into their new positions.
799
800 By default, this property is set. It may be cleared if
801 the main window contains widgets which are slow at resizing
802 or repainting themselves.
803
804 Setting this property is identical to setting the AnimatedDocks
805 option using setDockOptions().
806*/
807
808bool QMainWindow::isAnimated() const
809{
810 Q_D(const QMainWindow);
811 return d->layout->dockOptions & AnimatedDocks;
812}
813
814void QMainWindow::setAnimated(bool enabled)
815{
816 Q_D(QMainWindow);
817
818 DockOptions opts = d->layout->dockOptions;
819 opts.setFlag(AnimatedDocks, enabled);
820
821 d->layout->setDockOptions(opts);
822}
823
824/*! \property QMainWindow::dockNestingEnabled
825 \brief whether docks can be nested
826 \since 4.2
827
828 If this property is \c false, dock areas can only contain a single row
829 (horizontal or vertical) of dock widgets. If this property is \c true,
830 the area occupied by a dock widget can be split in either direction to contain
831 more dock widgets.
832
833 Dock nesting is only necessary in applications that contain a lot of
834 dock widgets. It gives the user greater freedom in organizing their
835 main window. However, dock nesting leads to more complex
836 (and less intuitive) behavior when a dock widget is dragged over the
837 main window, since there are more ways in which a dropped dock widget
838 may be placed in the dock area.
839
840 Setting this property is identical to setting the AllowNestedDocks option
841 using setDockOptions().
842*/
843
844bool QMainWindow::isDockNestingEnabled() const
845{
846 Q_D(const QMainWindow);
847 return d->layout->dockOptions & AllowNestedDocks;
848}
849
850void QMainWindow::setDockNestingEnabled(bool enabled)
851{
852 Q_D(QMainWindow);
853
854 DockOptions opts = d->layout->dockOptions;
855 opts.setFlag(AllowNestedDocks, enabled);
856
857 d->layout->setDockOptions(opts);
858}
859
860#if 0
861// If added back in, add the '!' to the qdoc comment marker as well.
862/*
863 \property QMainWindow::verticalTabsEnabled
864 \brief whether left and right dock areas use vertical tabs
865 \since 4.2
866
867 If this property is set to false, dock areas containing tabbed dock widgets
868 display horizontal tabs, similar to Visual Studio.
869
870 If this property is set to true, then the right and left dock areas display vertical
871 tabs, similar to KDevelop.
872
873 This property should be set before any dock widgets are added to the main window.
874*/
875
876bool QMainWindow::verticalTabsEnabled() const
877{
878 return d_func()->layout->verticalTabsEnabled();
879}
880
881void QMainWindow::setVerticalTabsEnabled(bool enabled)
882{
883 d_func()->layout->setVerticalTabsEnabled(enabled);
884}
885#endif
886
887static bool checkDockWidgetArea(Qt::DockWidgetArea area, const char *where)
888{
889 switch (area) {
890 case Qt::LeftDockWidgetArea:
891 case Qt::RightDockWidgetArea:
892 case Qt::TopDockWidgetArea:
893 case Qt::BottomDockWidgetArea:
894 return true;
895 default:
896 break;
897 }
898 qWarning("%s: invalid 'area' argument", where);
899 return false;
900}
901
902#if QT_CONFIG(tabbar)
903/*!
904 \property QMainWindow::documentMode
905 \brief whether the tab bar for tabbed dockwidgets is set to document mode.
906 \since 4.5
907
908 The default is false.
909
910 \sa QTabBar::documentMode
911*/
912bool QMainWindow::documentMode() const
913{
914 return d_func()->layout->documentMode();
915}
916
917void QMainWindow::setDocumentMode(bool enabled)
918{
919 d_func()->layout->setDocumentMode(enabled);
920}
921#endif // QT_CONFIG(tabbar)
922
923#if QT_CONFIG(tabwidget)
924/*!
925 \property QMainWindow::tabShape
926 \brief the tab shape used for tabbed dock widgets.
927 \since 4.5
928
929 The default is \l QTabWidget::Rounded.
930
931 \sa setTabPosition()
932*/
933QTabWidget::TabShape QMainWindow::tabShape() const
934{
935 return d_func()->layout->tabShape();
936}
937
938void QMainWindow::setTabShape(QTabWidget::TabShape tabShape)
939{
940 d_func()->layout->setTabShape(tabShape);
941}
942
943/*!
944 \since 4.5
945
946 Returns the tab position for \a area.
947
948 \note The \l VerticalTabs dock option overrides the tab positions returned
949 by this function.
950
951 \sa setTabPosition(), tabShape()
952*/
953QTabWidget::TabPosition QMainWindow::tabPosition(Qt::DockWidgetArea area) const
954{
955 if (!checkDockWidgetArea(area, "QMainWindow::tabPosition"))
956 return QTabWidget::South;
957 return d_func()->layout->tabPosition(area);
958}
959
960/*!
961 \since 4.5
962
963 Sets the tab position for the given dock widget \a areas to the specified
964 \a tabPosition. By default, all dock areas show their tabs at the bottom.
965
966 \note The \l VerticalTabs dock option overrides the tab positions set by
967 this method.
968
969 \sa tabPosition(), setTabShape()
970*/
971void QMainWindow::setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition)
972{
973 d_func()->layout->setTabPosition(areas, tabPosition);
974}
975#endif // QT_CONFIG(tabwidget)
976
977/*!
978 Adds the given \a dockwidget to the specified \a area.
979*/
980void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget)
981{
982 if (!checkDockWidgetArea(area, "QMainWindow::addDockWidget"))
983 return;
984
985 Qt::Orientation orientation = Qt::Vertical;
986 switch (area) {
987 case Qt::TopDockWidgetArea:
988 case Qt::BottomDockWidgetArea:
989 orientation = Qt::Horizontal;
990 break;
991 default:
992 break;
993 }
994 const Qt::DockWidgetArea oldArea = dockWidgetArea(dockwidget);
995 d_func()->layout->removeWidget(dockwidget); // in case it was already in here
996 addDockWidget(area, dockwidget, orientation);
997 if (oldArea != area)
998 emit dockwidget->dockLocationChanged(area);
999}
1000
1001/*!
1002 Restores the state of \a dockwidget if it is created after the call
1003 to restoreState(). Returns \c true if the state was restored; otherwise
1004 returns \c false.
1005
1006 \sa restoreState(), saveState()
1007*/
1008
1009bool QMainWindow::restoreDockWidget(QDockWidget *dockwidget)
1010{
1011 return d_func()->layout->restoreDockWidget(dockwidget);
1012}
1013
1014/*!
1015 Adds \a dockwidget into the given \a area in the direction
1016 specified by the \a orientation.
1017*/
1018void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget,
1019 Qt::Orientation orientation)
1020{
1021 if (!checkDockWidgetArea(area, "QMainWindow::addDockWidget"))
1022 return;
1023
1024 // add a window to an area, placing done relative to the previous
1025 d_func()->layout->addDockWidget(area, dockwidget, orientation);
1026}
1027
1028/*!
1029 \fn void QMainWindow::splitDockWidget(QDockWidget *first, QDockWidget *second, Qt::Orientation orientation)
1030
1031 Splits the space covered by the \a first dock widget into two parts,
1032 moves the \a first dock widget into the first part, and moves the
1033 \a second dock widget into the second part.
1034
1035 The \a orientation specifies how the space is divided: A Qt::Horizontal
1036 split places the second dock widget to the right of the first; a
1037 Qt::Vertical split places the second dock widget below the first.
1038
1039 \e Note: if \a first is currently in a tabbed docked area, \a second will
1040 be added as a new tab, not as a neighbor of \a first. This is because a
1041 single tab can contain only one dock widget.
1042
1043 \e Note: The Qt::LayoutDirection influences the order of the dock widgets
1044 in the two parts of the divided area. When right-to-left layout direction
1045 is enabled, the placing of the dock widgets will be reversed.
1046
1047 \sa tabifyDockWidget(), addDockWidget(), removeDockWidget()
1048*/
1049void QMainWindow::splitDockWidget(QDockWidget *after, QDockWidget *dockwidget,
1050 Qt::Orientation orientation)
1051{
1052 d_func()->layout->splitDockWidget(after, dockwidget, orientation);
1053}
1054
1055#if QT_CONFIG(tabbar)
1056/*!
1057 \fn void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second)
1058
1059 Moves \a second dock widget on top of \a first dock widget, creating a tabbed
1060 docked area in the main window.
1061
1062 \sa tabifiedDockWidgets()
1063*/
1064void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second)
1065{
1066 d_func()->layout->tabifyDockWidget(first, second);
1067}
1068
1069
1070/*!
1071 \fn QList<QDockWidget*> QMainWindow::tabifiedDockWidgets(QDockWidget *dockwidget) const
1072
1073 Returns the dock widgets that are tabified together with \a dockwidget.
1074
1075 \since 4.5
1076 \sa tabifyDockWidget()
1077*/
1078
1079QList<QDockWidget*> QMainWindow::tabifiedDockWidgets(QDockWidget *dockwidget) const
1080{
1081 Q_D(const QMainWindow);
1082 return d->layout ? d->layout->tabifiedDockWidgets(dockwidget) : QList<QDockWidget *>();
1083}
1084#endif // QT_CONFIG(tabbar)
1085
1086
1087/*!
1088 Removes the \a dockwidget from the main window layout and hides
1089 it. Note that the \a dockwidget is \e not deleted.
1090*/
1091void QMainWindow::removeDockWidget(QDockWidget *dockwidget)
1092{
1093 if (dockwidget) {
1094 d_func()->layout->removeWidget(dockwidget);
1095 dockwidget->hide();
1096 }
1097}
1098
1099/*!
1100 Returns the Qt::DockWidgetArea for \a dockwidget. If \a dockwidget
1101 has not been added to the main window, this function returns \c
1102 Qt::NoDockWidgetArea.
1103
1104 \sa addDockWidget(), splitDockWidget(), Qt::DockWidgetArea
1105*/
1106Qt::DockWidgetArea QMainWindow::dockWidgetArea(QDockWidget *dockwidget) const
1107{ return d_func()->layout->dockWidgetArea(dockwidget); }
1108
1109
1110/*!
1111 \since 5.6
1112 Resizes the dock widgets in the list \a docks to the corresponding size in
1113 pixels from the list \a sizes. If \a orientation is Qt::Horizontal, adjusts
1114 the width, otherwise adjusts the height of the dock widgets.
1115 The sizes will be adjusted such that the maximum and the minimum sizes are
1116 respected and the QMainWindow itself will not be resized.
1117 Any additional/missing space is distributed amongst the widgets according
1118 to the relative weight of the sizes.
1119
1120 Example:
1121 \snippet code/src_widgets_widgets_qmainwindow.cpp 2
1122
1123 If the blue and the yellow widget are nested on the same level they will be
1124 resized such that the yellowWidget is twice as big as the blueWidget
1125
1126 If some widgets are grouped in tabs, only one widget per group should be
1127 specified. Widgets not in the list might be changed to respect the constraints.
1128*/
1129void QMainWindow::resizeDocks(const QList<QDockWidget *> &docks,
1130 const QList<int> &sizes, Qt::Orientation orientation)
1131{
1132 d_func()->layout->layoutState.dockAreaLayout.resizeDocks(docks, sizes, orientation);
1133 d_func()->layout->invalidate();
1134}
1135
1136
1137#endif // QT_CONFIG(dockwidget)
1138
1139/*!
1140 Saves the current state of this mainwindow's toolbars and
1141 dockwidgets. This includes the corner settings which can
1142 be set with setCorner(). The \a version number is stored
1143 as part of the data.
1144
1145 The \l{QObject::objectName}{objectName} property is used
1146 to identify each QToolBar and QDockWidget. You should make sure
1147 that this property is unique for each QToolBar and QDockWidget you
1148 add to the QMainWindow
1149
1150 To restore the saved state, pass the return value and \a version
1151 number to restoreState().
1152
1153 To save the geometry when the window closes, you can
1154 implement a close event like this:
1155
1156 \snippet code/src_gui_widgets_qmainwindow.cpp 0
1157
1158 \sa restoreState(), QWidget::saveGeometry(), QWidget::restoreGeometry()
1159*/
1160QByteArray QMainWindow::saveState(int version) const
1161{
1162 QByteArray data;
1163 QDataStream stream(&data, QIODevice::WriteOnly);
1164 stream.setVersion(QDataStream::Qt_5_0);
1165 stream << QMainWindowLayout::VersionMarker;
1166 stream << version;
1167 d_func()->layout->saveState(stream);
1168 return data;
1169}
1170
1171/*!
1172 Restores the \a state of this mainwindow's toolbars and
1173 dockwidgets. Also restores the corner settings too. The
1174 \a version number is compared with that stored in \a state.
1175 If they do not match, the mainwindow's state is left
1176 unchanged, and this function returns \c false; otherwise, the state
1177 is restored, and this function returns \c true.
1178
1179 To restore geometry saved using QSettings, you can use code like
1180 this:
1181
1182 \snippet code/src_gui_widgets_qmainwindow.cpp 1
1183
1184 \sa saveState(), QWidget::saveGeometry(),
1185 QWidget::restoreGeometry(), restoreDockWidget()
1186*/
1187bool QMainWindow::restoreState(const QByteArray &state, int version)
1188{
1189 if (state.isEmpty())
1190 return false;
1191 QByteArray sd = state;
1192 QDataStream stream(&sd, QIODevice::ReadOnly);
1193 stream.setVersion(QDataStream::Qt_5_0);
1194 int marker, v;
1195 stream >> marker;
1196 stream >> v;
1197 if (stream.status() != QDataStream::Ok || marker != QMainWindowLayout::VersionMarker || v != version)
1198 return false;
1199 bool restored = d_func()->layout->restoreState(stream);
1200 return restored;
1201}
1202
1203/*! \reimp */
1204bool QMainWindow::event(QEvent *event)
1205{
1206 Q_D(QMainWindow);
1207
1208#if QT_CONFIG(dockwidget)
1209 if (d->layout && d->layout->windowEvent(event))
1210 return true;
1211#endif
1212
1213 switch (event->type()) {
1214
1215#if QT_CONFIG(toolbar)
1216 case QEvent::ToolBarChange: {
1217 Q_ASSERT(d->layout);
1218 d->layout->toggleToolBarsVisible();
1219 return true;
1220 }
1221#endif
1222
1223#if QT_CONFIG(statustip)
1224 case QEvent::StatusTip:
1225#if QT_CONFIG(statusbar)
1226 Q_ASSERT(d->layout);
1227 if (QStatusBar *sb = d->layout->statusBar())
1228 sb->showMessage(static_cast<QStatusTipEvent*>(event)->tip());
1229 else
1230#endif
1231 static_cast<QStatusTipEvent*>(event)->ignore();
1232 return true;
1233#endif // QT_CONFIG(statustip)
1234
1235 case QEvent::StyleChange:
1236#if QT_CONFIG(dockwidget)
1237 Q_ASSERT(d->layout);
1238 d->layout->layoutState.dockAreaLayout.styleChangedEvent();
1239#endif
1240 if (!d->explicitIconSize)
1241 setIconSize(QSize());
1242 break;
1243#if QT_CONFIG(draganddrop)
1244 case QEvent::DragEnter:
1245 case QEvent::Drop:
1246 if (!d->layout->draggingWidget)
1247 break;
1248 event->accept();
1249 return true;
1250 case QEvent::DragMove: {
1251 if (!d->layout->draggingWidget)
1252 break;
1253 auto dragMoveEvent = static_cast<QDragMoveEvent *>(event);
1254 d->layout->hover(d->layout->draggingWidget,
1255 mapToGlobal(dragMoveEvent->position()).toPoint());
1256 event->accept();
1257 return true;
1258 }
1259 case QEvent::DragLeave:
1260 if (!d->layout->draggingWidget)
1261 break;
1262 d->layout->hover(d->layout->draggingWidget, pos() - QPoint(-1, -1));
1263 return true;
1264#endif
1265 default:
1266 break;
1267 }
1268
1269 return QWidget::event(event);
1270}
1271
1272#if QT_CONFIG(toolbar)
1273
1274/*!
1275 \property QMainWindow::unifiedTitleAndToolBarOnMac
1276 \brief whether the window uses the unified title and toolbar look on \macos
1277
1278 Note that the Qt 5 implementation has several limitations compared to Qt 4:
1279 \list
1280 \li Use in windows with OpenGL content is not supported. This includes QOpenGLWidget.
1281 \li Using dockable or movable toolbars may result in painting errors and is not recommended
1282 \endlist
1283
1284 \since 5.2
1285*/
1286void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool enabled)
1287{
1288#ifdef Q_OS_MACOS
1289 if (!isWindow())
1290 return;
1291
1292 Q_D(QMainWindow);
1293 d->useUnifiedToolBar = enabled;
1294
1295 // The unified toolbar is drawn by the macOS style with a transparent background.
1296 // To ensure a suitable surface format is used we need to first create backing
1297 // QWindow so we have something to update the surface format on, and then let
1298 // QWidget know about the translucency, which it will propagate to the surface.
1299 setAttribute(Qt::WA_NativeWindow);
1300 setAttribute(Qt::WA_TranslucentBackground, enabled);
1301
1302 d->create(); // Create first, before querying the platform window
1303 using namespace QNativeInterface::Private;
1304 if (auto *platformWindow = dynamic_cast<QCocoaWindow*>(window()->windowHandle()->handle()))
1305 platformWindow->setContentBorderEnabled(enabled);
1306
1307 update();
1308#else
1309 Q_UNUSED(enabled);
1310#endif
1311}
1312
1313bool QMainWindow::unifiedTitleAndToolBarOnMac() const
1314{
1315#ifdef Q_OS_MACOS
1316 return d_func()->useUnifiedToolBar;
1317#endif
1318 return false;
1319}
1320
1321#endif // QT_CONFIG(toolbar)
1322
1323/*!
1324 \internal
1325*/
1326bool QMainWindow::isSeparator(const QPoint &pos) const
1327{
1328#if QT_CONFIG(dockwidget)
1329 Q_D(const QMainWindow);
1330 return !d->layout->layoutState.dockAreaLayout.findSeparator(pos).isEmpty();
1331#else
1332 Q_UNUSED(pos);
1333 return false;
1334#endif
1335}
1336
1337#ifndef QT_NO_CONTEXTMENU
1338/*!
1339 \reimp
1340*/
1341void QMainWindow::contextMenuEvent(QContextMenuEvent *event)
1342{
1343 event->ignore();
1344 // only show the context menu for direct QDockWidget and QToolBar
1345 // children and for the menu bar as well
1346 QWidget *child = childAt(event->pos());
1347 while (child && child != this) {
1348#if QT_CONFIG(menubar)
1349 if (QMenuBar *mb = qobject_cast<QMenuBar *>(child)) {
1350 if (mb->parentWidget() != this)
1351 return;
1352 break;
1353 }
1354#endif
1355#if QT_CONFIG(dockwidget)
1356 if (QDockWidget *dw = qobject_cast<QDockWidget *>(child)) {
1357 if (dw->parentWidget() != this)
1358 return;
1359 if (dw->widget()
1360 && dw->widget()->geometry().contains(child->mapFrom(this, event->pos()))) {
1361 // ignore the event if the mouse is over the QDockWidget contents
1362 return;
1363 }
1364 break;
1365 }
1366#endif // QT_CONFIG(dockwidget)
1367#if QT_CONFIG(toolbar)
1368 if (QToolBar *tb = qobject_cast<QToolBar *>(child)) {
1369 if (tb->parentWidget() != this)
1370 return;
1371 break;
1372 }
1373#endif
1374 child = child->parentWidget();
1375 }
1376 if (child == this)
1377 return;
1378
1379#if QT_CONFIG(menu)
1380 QMenu *popup = createPopupMenu();
1381 if (popup) {
1382 if (!popup->isEmpty()) {
1383 popup->setAttribute(Qt::WA_DeleteOnClose);
1384 popup->popup(event->globalPos());
1385 event->accept();
1386 } else {
1387 delete popup;
1388 }
1389 }
1390#endif
1391}
1392#endif // QT_NO_CONTEXTMENU
1393
1394#if QT_CONFIG(menu)
1395/*!
1396 Returns a popup menu containing checkable entries for the toolbars and
1397 dock widgets present in the main window. If there are no toolbars and
1398 dock widgets present, this function returns \nullptr.
1399
1400 By default, this function is called by the main window when the user
1401 activates a context menu, typically by right-clicking on a toolbar or a dock
1402 widget.
1403
1404 If you want to create a custom popup menu, reimplement this function and
1405 return a newly-created popup menu. Ownership of the popup menu is transferred
1406 to the caller.
1407
1408 \sa addDockWidget(), addToolBar(), menuBar()
1409*/
1410QMenu *QMainWindow::createPopupMenu()
1411{
1412 Q_D(QMainWindow);
1413 QMenu *menu = nullptr;
1414#if QT_CONFIG(dockwidget)
1415 QList<QDockWidget *> dockwidgets = findChildren<QDockWidget *>();
1416 if (dockwidgets.size()) {
1417 menu = new QMenu(this);
1418 for (int i = 0; i < dockwidgets.size(); ++i) {
1419 QDockWidget *dockWidget = dockwidgets.at(i);
1420 // filter to find out if we own this QDockWidget
1421 if (dockWidget->parentWidget() == this) {
1422 if (d->layout->layoutState.dockAreaLayout.indexOf(dockWidget).isEmpty())
1423 continue;
1424 } else if (QDockWidgetGroupWindow *dwgw =
1425 qobject_cast<QDockWidgetGroupWindow *>(dockWidget->parentWidget())) {
1426 if (dwgw->parentWidget() != this)
1427 continue;
1428 if (dwgw->layoutInfo()->indexOf(dockWidget).isEmpty())
1429 continue;
1430 } else {
1431 continue;
1432 }
1433 menu->addAction(dockwidgets.at(i)->toggleViewAction());
1434 }
1435 menu->addSeparator();
1436 }
1437#endif // QT_CONFIG(dockwidget)
1438#if QT_CONFIG(toolbar)
1439 QList<QToolBar *> toolbars = findChildren<QToolBar *>();
1440 if (toolbars.size()) {
1441 if (!menu)
1442 menu = new QMenu(this);
1443 for (int i = 0; i < toolbars.size(); ++i) {
1444 QToolBar *toolBar = toolbars.at(i);
1445 if (toolBar->parentWidget() == this
1446 && (!d->layout->layoutState.toolBarAreaLayout.indexOf(toolBar).isEmpty())) {
1447 menu->addAction(toolbars.at(i)->toggleViewAction());
1448 }
1449 }
1450 }
1451#endif
1452 Q_UNUSED(d);
1453 return menu;
1454}
1455#endif // QT_CONFIG(menu)
1456
1457QT_END_NAMESPACE
1458
1459#include "moc_qmainwindow.cpp"
Qt::ToolButtonStyle toolButtonStyle
static QMainWindowLayout * mainWindowLayout(const QMainWindow *mainWindow)
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *mainWindow)