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 in the main window.
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 dock area at the current location of \a first.
1061
1062 Both dock widgets must have been added to the main window with
1063 addDockWidget() before calling this function, and neither can already be tabbed.
1064
1065 \sa tabifiedDockWidgets(), addDockWidget()
1066*/
1067void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second)
1068{
1069 d_func()->layout->tabifyDockWidget(first, second);
1070}
1071
1072
1073/*!
1074 \fn QList<QDockWidget*> QMainWindow::tabifiedDockWidgets(QDockWidget *dockwidget) const
1075
1076 Returns the dock widgets that are tabified together with \a dockwidget.
1077
1078 \since 4.5
1079 \sa tabifyDockWidget()
1080*/
1081
1082QList<QDockWidget*> QMainWindow::tabifiedDockWidgets(QDockWidget *dockwidget) const
1083{
1084 Q_D(const QMainWindow);
1085 return d->layout ? d->layout->tabifiedDockWidgets(dockwidget) : QList<QDockWidget *>();
1086}
1087#endif // QT_CONFIG(tabbar)
1088
1089
1090/*!
1091 Removes the \a dockwidget from the main window layout and hides
1092 it. Note that the \a dockwidget is \e not deleted.
1093*/
1094void QMainWindow::removeDockWidget(QDockWidget *dockwidget)
1095{
1096 if (dockwidget) {
1097 d_func()->layout->removeWidget(dockwidget);
1098 dockwidget->hide();
1099 }
1100}
1101
1102/*!
1103 Returns the Qt::DockWidgetArea for \a dockwidget. If \a dockwidget
1104 has not been added to the main window, this function returns \c
1105 Qt::NoDockWidgetArea.
1106
1107 \sa addDockWidget(), splitDockWidget(), Qt::DockWidgetArea
1108*/
1109Qt::DockWidgetArea QMainWindow::dockWidgetArea(QDockWidget *dockwidget) const
1110{ return d_func()->layout->dockWidgetArea(dockwidget); }
1111
1112
1113/*!
1114 \since 5.6
1115 Resizes the dock widgets in the list \a docks to the corresponding size in
1116 pixels from the list \a sizes. If \a orientation is Qt::Horizontal, adjusts
1117 the width, otherwise adjusts the height of the dock widgets.
1118 The sizes will be adjusted such that the maximum and the minimum sizes are
1119 respected and the QMainWindow itself will not be resized.
1120 Any additional/missing space is distributed amongst the widgets according
1121 to the relative weight of the sizes.
1122
1123 Example:
1124 \snippet code/src_widgets_widgets_qmainwindow.cpp 2
1125
1126 If the blue and the yellow widget are nested on the same level they will be
1127 resized such that the yellowWidget is twice as big as the blueWidget
1128
1129 If some widgets are grouped in tabs, only one widget per group should be
1130 specified. Widgets not in the list might be changed to respect the constraints.
1131*/
1132void QMainWindow::resizeDocks(const QList<QDockWidget *> &docks,
1133 const QList<int> &sizes, Qt::Orientation orientation)
1134{
1135 d_func()->layout->layoutState.dockAreaLayout.resizeDocks(docks, sizes, orientation);
1136 d_func()->layout->invalidate();
1137}
1138
1139
1140#endif // QT_CONFIG(dockwidget)
1141
1142/*!
1143 Saves the current state of this mainwindow's toolbars and
1144 dockwidgets. This includes the corner settings which can
1145 be set with setCorner(). The \a version number is stored
1146 as part of the data.
1147
1148 The \l{QObject::objectName}{objectName} property is used
1149 to identify each QToolBar and QDockWidget. You should make sure
1150 that this property is unique for each QToolBar and QDockWidget you
1151 add to the QMainWindow
1152
1153 To restore the saved state, pass the return value and \a version
1154 number to restoreState().
1155
1156 To save the geometry when the window closes, you can
1157 implement a close event like this:
1158
1159 \snippet code/src_gui_widgets_qmainwindow.cpp 0
1160
1161 \sa restoreState(), QWidget::saveGeometry(), QWidget::restoreGeometry()
1162*/
1163QByteArray QMainWindow::saveState(int version) const
1164{
1165 QByteArray data;
1166 QDataStream stream(&data, QIODevice::WriteOnly);
1167 stream.setVersion(QDataStream::Qt_5_0);
1168 stream << QMainWindowLayout::VersionMarker;
1169 stream << version;
1170 d_func()->layout->saveState(stream);
1171 return data;
1172}
1173
1174/*!
1175 Restores the \a state of this mainwindow's toolbars and
1176 dockwidgets. Also restores the corner settings too. The
1177 \a version number is compared with that stored in \a state.
1178 If they do not match, the mainwindow's state is left
1179 unchanged, and this function returns \c false; otherwise, the state
1180 is restored, and this function returns \c true.
1181
1182 To restore geometry saved using QSettings, you can use code like
1183 this:
1184
1185 \snippet code/src_gui_widgets_qmainwindow.cpp 1
1186
1187 \sa saveState(), QWidget::saveGeometry(),
1188 QWidget::restoreGeometry(), restoreDockWidget()
1189*/
1190bool QMainWindow::restoreState(const QByteArray &state, int version)
1191{
1192 if (state.isEmpty())
1193 return false;
1194 QByteArray sd = state;
1195 QDataStream stream(&sd, QIODevice::ReadOnly);
1196 stream.setVersion(QDataStream::Qt_5_0);
1197 int marker, v;
1198 stream >> marker;
1199 stream >> v;
1200 if (stream.status() != QDataStream::Ok || marker != QMainWindowLayout::VersionMarker || v != version)
1201 return false;
1202 bool restored = d_func()->layout->restoreState(stream);
1203 return restored;
1204}
1205
1206/*! \reimp */
1207bool QMainWindow::event(QEvent *event)
1208{
1209 Q_D(QMainWindow);
1210
1211#if QT_CONFIG(dockwidget)
1212 if (d->layout && d->layout->windowEvent(event))
1213 return true;
1214#endif
1215
1216 switch (event->type()) {
1217
1218#if QT_CONFIG(toolbar)
1219 case QEvent::ToolBarChange: {
1220 Q_ASSERT(d->layout);
1221 d->layout->toggleToolBarsVisible();
1222 return true;
1223 }
1224#endif
1225
1226#if QT_CONFIG(statustip)
1227 case QEvent::StatusTip:
1228#if QT_CONFIG(statusbar)
1229 Q_ASSERT(d->layout);
1230 if (QStatusBar *sb = d->layout->statusBar())
1231 sb->showMessage(static_cast<QStatusTipEvent*>(event)->tip());
1232 else
1233#endif
1234 static_cast<QStatusTipEvent*>(event)->ignore();
1235 return true;
1236#endif // QT_CONFIG(statustip)
1237
1238 case QEvent::StyleChange:
1239#if QT_CONFIG(dockwidget)
1240 Q_ASSERT(d->layout);
1241 d->layout->layoutState.dockAreaLayout.styleChangedEvent();
1242#endif
1243 if (!d->explicitIconSize)
1244 setIconSize(QSize());
1245 break;
1246#if QT_CONFIG(draganddrop)
1247 case QEvent::DragEnter:
1248 case QEvent::Drop:
1249 if (!d->layout->draggingWidget)
1250 break;
1251 event->accept();
1252 return true;
1253 case QEvent::DragMove: {
1254 if (!d->layout->draggingWidget)
1255 break;
1256 auto dragMoveEvent = static_cast<QDragMoveEvent *>(event);
1257 d->layout->hover(d->layout->draggingWidget,
1258 mapToGlobal(dragMoveEvent->position()).toPoint());
1259 event->accept();
1260 return true;
1261 }
1262 case QEvent::DragLeave:
1263 if (!d->layout->draggingWidget)
1264 break;
1265 d->layout->hover(d->layout->draggingWidget, pos() - QPoint(-1, -1));
1266 return true;
1267#endif
1268 default:
1269 break;
1270 }
1271
1272 return QWidget::event(event);
1273}
1274
1275#if QT_CONFIG(toolbar)
1276
1277/*!
1278 \property QMainWindow::unifiedTitleAndToolBarOnMac
1279 \brief whether the window uses the unified title and toolbar look on \macos
1280
1281 Note that the Qt 5 implementation has several limitations compared to Qt 4:
1282 \list
1283 \li Use in windows with OpenGL content is not supported. This includes QOpenGLWidget.
1284 \li Using dockable or movable toolbars may result in painting errors and is not recommended
1285 \endlist
1286
1287 \since 5.2
1288*/
1289void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool enabled)
1290{
1291#ifdef Q_OS_MACOS
1292 if (!isWindow())
1293 return;
1294
1295 Q_D(QMainWindow);
1296 d->useUnifiedToolBar = enabled;
1297
1298 // The unified toolbar is drawn by the macOS style with a transparent background.
1299 // To ensure a suitable surface format is used we need to first create backing
1300 // QWindow so we have something to update the surface format on, and then let
1301 // QWidget know about the translucency, which it will propagate to the surface.
1302 setAttribute(Qt::WA_NativeWindow);
1303 setAttribute(Qt::WA_TranslucentBackground, enabled);
1304
1305 d->create(); // Create first, before querying the platform window
1306 using namespace QNativeInterface::Private;
1307 if (auto *platformWindow = dynamic_cast<QCocoaWindow*>(window()->windowHandle()->handle()))
1308 platformWindow->setContentBorderEnabled(enabled);
1309
1310 update();
1311#else
1312 Q_UNUSED(enabled);
1313#endif
1314}
1315
1316bool QMainWindow::unifiedTitleAndToolBarOnMac() const
1317{
1318#ifdef Q_OS_MACOS
1319 return d_func()->useUnifiedToolBar;
1320#endif
1321 return false;
1322}
1323
1324#endif // QT_CONFIG(toolbar)
1325
1326/*!
1327 \internal
1328*/
1329bool QMainWindow::isSeparator(const QPoint &pos) const
1330{
1331#if QT_CONFIG(dockwidget)
1332 Q_D(const QMainWindow);
1333 return !d->layout->layoutState.dockAreaLayout.findSeparator(pos).isEmpty();
1334#else
1335 Q_UNUSED(pos);
1336 return false;
1337#endif
1338}
1339
1340#ifndef QT_NO_CONTEXTMENU
1341/*!
1342 \reimp
1343*/
1344void QMainWindow::contextMenuEvent(QContextMenuEvent *event)
1345{
1346 event->ignore();
1347 // only show the context menu for direct QDockWidget and QToolBar
1348 // children and for the menu bar as well
1349 QWidget *child = childAt(event->pos());
1350 while (child && child != this) {
1351#if QT_CONFIG(menubar)
1352 if (QMenuBar *mb = qobject_cast<QMenuBar *>(child)) {
1353 if (mb->parentWidget() != this)
1354 return;
1355 break;
1356 }
1357#endif
1358#if QT_CONFIG(dockwidget)
1359 if (QDockWidget *dw = qobject_cast<QDockWidget *>(child)) {
1360 if (dw->parentWidget() != this)
1361 return;
1362 if (dw->widget()
1363 && dw->widget()->geometry().contains(child->mapFrom(this, event->pos()))) {
1364 // ignore the event if the mouse is over the QDockWidget contents
1365 return;
1366 }
1367 break;
1368 }
1369#endif // QT_CONFIG(dockwidget)
1370#if QT_CONFIG(toolbar)
1371 if (QToolBar *tb = qobject_cast<QToolBar *>(child)) {
1372 if (tb->parentWidget() != this)
1373 return;
1374 break;
1375 }
1376#endif
1377 child = child->parentWidget();
1378 }
1379 if (child == this)
1380 return;
1381
1382#if QT_CONFIG(menu)
1383 QMenu *popup = createPopupMenu();
1384 if (popup) {
1385 if (!popup->isEmpty()) {
1386 popup->setAttribute(Qt::WA_DeleteOnClose);
1387 popup->popup(event->globalPos());
1388 event->accept();
1389 } else {
1390 delete popup;
1391 }
1392 }
1393#endif
1394}
1395#endif // QT_NO_CONTEXTMENU
1396
1397#if QT_CONFIG(menu)
1398/*!
1399 Returns a popup menu containing checkable entries for the toolbars and
1400 dock widgets present in the main window. If there are no toolbars and
1401 dock widgets present, this function returns \nullptr.
1402
1403 By default, this function is called by the main window when the user
1404 activates a context menu, typically by right-clicking on a toolbar or a dock
1405 widget.
1406
1407 If you want to create a custom popup menu, reimplement this function and
1408 return a newly-created popup menu. Ownership of the popup menu is transferred
1409 to the caller.
1410
1411 \sa addDockWidget(), addToolBar(), menuBar()
1412*/
1413QMenu *QMainWindow::createPopupMenu()
1414{
1415 Q_D(QMainWindow);
1416 QMenu *menu = nullptr;
1417#if QT_CONFIG(dockwidget)
1418 QList<QDockWidget *> dockwidgets = findChildren<QDockWidget *>();
1419 if (dockwidgets.size()) {
1420 menu = new QMenu(this);
1421 for (int i = 0; i < dockwidgets.size(); ++i) {
1422 QDockWidget *dockWidget = dockwidgets.at(i);
1423 // filter to find out if we own this QDockWidget
1424 if (dockWidget->parentWidget() == this) {
1425 if (d->layout->layoutState.dockAreaLayout.indexOf(dockWidget).isEmpty())
1426 continue;
1427 } else if (QDockWidgetGroupWindow *dwgw =
1428 qobject_cast<QDockWidgetGroupWindow *>(dockWidget->parentWidget())) {
1429 if (dwgw->parentWidget() != this)
1430 continue;
1431 if (dwgw->layoutInfo()->indexOf(dockWidget).isEmpty())
1432 continue;
1433 } else {
1434 continue;
1435 }
1436 menu->addAction(dockwidgets.at(i)->toggleViewAction());
1437 }
1438 menu->addSeparator();
1439 }
1440#endif // QT_CONFIG(dockwidget)
1441#if QT_CONFIG(toolbar)
1442 QList<QToolBar *> toolbars = findChildren<QToolBar *>();
1443 if (toolbars.size()) {
1444 if (!menu)
1445 menu = new QMenu(this);
1446 for (int i = 0; i < toolbars.size(); ++i) {
1447 QToolBar *toolBar = toolbars.at(i);
1448 if (toolBar->parentWidget() == this
1449 && (!d->layout->layoutState.toolBarAreaLayout.indexOf(toolBar).isEmpty())) {
1450 menu->addAction(toolbars.at(i)->toggleViewAction());
1451 }
1452 }
1453 }
1454#endif
1455 Q_UNUSED(d);
1456 return menu;
1457}
1458#endif // QT_CONFIG(menu)
1459
1460QT_END_NAMESPACE
1461
1462#include "moc_qmainwindow.cpp"
Qt::ToolButtonStyle toolButtonStyle
static QMainWindowLayout * mainWindowLayout(const QMainWindow *mainWindow)
Combined button and popup list for selecting options.
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *mainWindow)