CopperSpice API  1.7.2
QMainWindow Class Reference

QMainWindow class provides the main GUI application window. More...

Inheritance diagram for QMainWindow:
QWidget QObject QPaintDevice

Public Typedefs

using DockOptions = QFlags< DockOption >
 

Public Types

enum  DockOption
 
- Public Types inherited from QWidget
enum  RenderFlag
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 

Public Signals

void iconSizeChanged (const QSize &iconSize)
 
void toolButtonStyleChanged (Qt::ToolButtonStyle toolButtonStyle)
 
- Public Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 
void windowIconChanged (const QIcon &icon)
 
void windowIconTextChanged (const QString &iconText)
 
void windowTitleChanged (const QString &title)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void setAnimated (bool enabled)
 
void setDockNestingEnabled (bool enabled)
 
void setUnifiedTitleAndToolBarOnMac (bool set)
 
- Public Slots inherited from QWidget
bool close ()
 
void hide ()
 
void lower ()
 
void raise ()
 
void repaint ()
 
void setDisabled (bool disable)
 
void setEnabled (bool enable)
 
void setFocus ()
 
void setHidden (bool hidden)
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool modified)
 
void setWindowTitle (const QString &title)
 
void show ()
 
void showFullScreen ()
 
void showMaximized ()
 
void showMinimized ()
 
void showNormal ()
 
void update ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QMainWindow (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QMainWindow ()
 
void addDockWidget (Qt::DockWidgetArea area, QDockWidget *dockwidget)
 
void addDockWidget (Qt::DockWidgetArea area, QDockWidget *dockwidget, Qt::Orientation orientation)
 
QToolBaraddToolBar (const QString &title)
 
void addToolBar (Qt::ToolBarArea area, QToolBar *toolbar)
 
void addToolBar (QToolBar *toolbar)
 
void addToolBarBreak (Qt::ToolBarArea area=Qt::TopToolBarArea)
 
QWidgetcentralWidget () const
 
Qt::DockWidgetArea corner (Qt::Corner corner) const
 
virtual QMenucreatePopupMenu ()
 
DockOptions dockOptions () const
 
Qt::DockWidgetArea dockWidgetArea (QDockWidget *dockwidget) const
 
bool documentMode () const
 
QSize iconSize () const
 
void insertToolBar (QToolBar *before, QToolBar *toolbar)
 
void insertToolBarBreak (QToolBar *before)
 
bool isAnimated () const
 
bool isDockNestingEnabled () const
 
QMenuBarmenuBar () const
 
QWidgetmenuWidget () const
 
void removeDockWidget (QDockWidget *dockwidget)
 
void removeToolBar (QToolBar *toolbar)
 
void removeToolBarBreak (QToolBar *before)
 
void resizeDocks (const QList< QDockWidget * > &docks, const QList< int > &sizes, Qt::Orientation orientation)
 
bool restoreDockWidget (QDockWidget *dockwidget)
 
bool restoreState (const QByteArray &state, int version=0)
 
QByteArray saveState (int version=0) const
 
void setCentralWidget (QWidget *widget)
 
void setCorner (Qt::Corner corner, Qt::DockWidgetArea area)
 
void setDockOptions (DockOptions options)
 
void setDocumentMode (bool enabled)
 
void setIconSize (const QSize &iconSize)
 
void setMenuBar (QMenuBar *menuBar)
 
void setMenuWidget (QWidget *menuBar)
 
void setStatusBar (QStatusBar *statusbar)
 
void setTabPosition (Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition)
 
void setTabShape (QTabWidget::TabShape tabShape)
 
void setToolButtonStyle (Qt::ToolButtonStyle toolButtonStyle)
 
void splitDockWidget (QDockWidget *first, QDockWidget *second, Qt::Orientation orientation)
 
QStatusBarstatusBar () const
 
QList< QDockWidget * > tabifiedDockWidgets (QDockWidget *dockwidget) const
 
void tabifyDockWidget (QDockWidget *first, QDockWidget *second)
 
QTabWidget::TabPosition tabPosition (Qt::DockWidgetArea area) const
 
QTabWidget::TabShape tabShape () const
 
QWidgettakeCentralWidget ()
 
Qt::ToolBarArea toolBarArea (QToolBar *toolbar) const
 
bool toolBarBreak (QToolBar *toolbar) const
 
Qt::ToolButtonStyle toolButtonStyle () const
 
bool unifiedTitleAndToolBarOnMac () const
 
- Public Methods inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QWidget ()
 
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 
void activateWindow ()
 
void addAction (QAction *action)
 
void addActions (const QList< QAction * > &actions)
 
void adjustSize ()
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 
QBackingStorebackingStore () const
 
QSize baseSize () const
 
QWidget * childAt (const QPoint &position) const
 
QWidget * childAt (int x, int y) const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 
void clearMask ()
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
QCursor cursor () const
 
WId effectiveWinId () const
 
void ensurePolished () const
 
Qt::FocusPolicy focusPolicy () const
 
QWidget * focusProxy () const
 
QWidget * focusWidget () const
 
const QFontfont () const
 
QFontInfo fontInfo () const
 
QFontMetrics fontMetrics () const
 
QPalette::ColorRole foregroundRole () const
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QPixmap grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1)))
 
void grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ())
 
void grabKeyboard ()
 
void grabMouse ()
 
void grabMouse (const QCursor &cursor)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 
QGraphicsEffectgraphicsEffect () const
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 
bool hasEditFocus () const
 
bool hasFocus () const
 
virtual bool hasHeightForWidth () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int width) const
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
void insertAction (QAction *before, QAction *action)
 
void insertActions (QAction *before, QList< QAction * > actions)
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *parent) const
 
bool isEnabledToTLW () const
 
bool isFullScreen () const
 
bool isHidden () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isTopLevel () const
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *parent) const
 
bool isWindow () const
 
bool isWindowModified () const
 
QLayoutlayout () const
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
QPoint mapFrom (const QWidget *parent, const QPoint &pos) const
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapFromParent (const QPoint &pos) const
 
QPoint mapTo (const QWidget *parent, const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QPoint mapToParent (const QPoint &pos) const
 
QRegion mask () const
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
virtual QSize minimumSizeHint () const
 
int minimumWidth () const
 
void move (const QPoint &point)
 
void move (int x, int y)
 
QWidget * nativeParentWidget () const
 
QWidget * nextInFocusChain () const
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags flags)
 
QPaintEnginepaintEngine () const override
 
const QPalettepalette () const
 
QWidget * parentWidget () const
 
QPoint pos () const
 
QWidget * previousInFocusChain () const
 
QRect rect () const
 
void releaseKeyboard ()
 
void releaseMouse ()
 
void releaseShortcut (int id)
 
void removeAction (QAction *action)
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void repaint (const QRect &rect)
 
void repaint (const QRegion &region)
 
void repaint (int x, int y, int w, int h)
 
void resize (const QSize &size)
 
void resize (int w, int h)
 
bool restoreGeometry (const QByteArray &geometry)
 
QByteArray saveGeometry () const
 
void scroll (int dx, int dy)
 
void scroll (int dx, int dy, const QRect &rect)
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute attribute, bool enable=true)
 
void setAutoFillBackground (bool enable)
 
void setBackgroundRole (QPalette::ColorRole role)
 
void setBaseSize (const QSize &size)
 
void setBaseSize (int basew, int baseh)
 
void setContentsMargins (const QMargins &margins)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &cursor)
 
void setEditFocus (bool enable)
 
void setFixedHeight (int h)
 
void setFixedSize (const QSize &size)
 
void setFixedSize (int w, int h)
 
void setFixedWidth (int w)
 
void setFocus (Qt::FocusReason reason)
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *widget)
 
void setFont (const QFont &font)
 
void setForegroundRole (QPalette::ColorRole role)
 
void setGeometry (const QRect &rect)
 
void setGeometry (int x, int y, int w, int h)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *layout)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &bitmap)
 
void setMask (const QRegion &region)
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &size)
 
void setMaximumSize (int maxw, int maxh)
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &size)
 
void setMinimumSize (int minw, int minh)
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &palette)
 
void setParent (QWidget *parent)
 
void setParent (QWidget *parent, Qt::WindowFlags flags)
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
void setShortcutEnabled (int id, bool enable=true)
 
void setSizeIncrement (const QSize &size)
 
void setSizeIncrement (int w, int h)
 
void setSizePolicy (QSizePolicy policy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
void setStatusTip (const QString &data)
 
void setStyle (QStyle *style)
 
void setToolTip (const QString &data)
 
void setToolTipDuration (int msec)
 
void setUpdatesEnabled (bool enable)
 
void setWhatsThis (const QString &str)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags flags)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &role)
 
void setWindowState (Qt::WindowStates windowState)
 
QSize size () const
 
virtual QSize sizeHint () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *widget)
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute attribute) const
 
QString toolTip () const
 
int toolTipDuration () const
 
QWidget * topLevelWidget () const
 
bool underMouse () const
 
void ungrabGesture (Qt::GestureType gestureType)
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (const QRect &rect)
 
void update (const QRegion &region)
 
void update (int x, int y, int w, int h)
 
void updateGeometry ()
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 
QString whatsThis () const
 
int width () const
 
QWidget * window () const
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 
QWindowwindowHandle () const
 
QIcon windowIcon () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 
Qt::WindowStates windowState () const
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 
WId winId () const
 
int x () const
 
int y () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Protected Methods

void contextMenuEvent (QContextMenuEvent *event) override
 
bool event (QEvent *event) override
 
- Protected Methods inherited from QWidget
virtual void actionEvent (QActionEvent *event)
 
virtual void changeEvent (QEvent *event)
 
virtual void closeEvent (QCloseEvent *event)
 
void create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true)
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 
virtual void dragEnterEvent (QDragEnterEvent *event)
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event)
 
virtual void dropEvent (QDropEvent *event)
 
virtual void enterEvent (QEvent *event)
 
bool event (QEvent *event) override
 
virtual void focusInEvent (QFocusEvent *event)
 
bool focusNextChild ()
 
virtual bool focusNextPrevChild (bool next)
 
virtual void focusOutEvent (QFocusEvent *event)
 
bool focusPreviousChild ()
 
virtual void hideEvent (QHideEvent *event)
 
void initPainter (QPainter *painter) const override
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
virtual void leaveEvent (QEvent *event)
 
int metric (PaintDeviceMetric metric) const override
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 
virtual void mouseMoveEvent (QMouseEvent *event)
 
virtual void mousePressEvent (QMouseEvent *event)
 
virtual void mouseReleaseEvent (QMouseEvent *event)
 
virtual void moveEvent (QMoveEvent *event)
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, long *result)
 
virtual void paintEvent (QPaintEvent *event)
 
virtual void resizeEvent (QResizeEvent *event)
 
virtual void showEvent (QShowEvent *event)
 
virtual void tabletEvent (QTabletEvent *event)
 
virtual void wheelEvent (QWheelEvent *event)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Properties

 animated
 
 dockNestingEnabled
 
 dockOptions
 
 documentMode
 
 iconSize
 
 tabShape
 
 toolButtonStyle
 
 unifiedTitleAndToolBarOnMac
 
- Properties inherited from QWidget
 acceptDrops
 
 accessibleDescription
 
 accessibleName
 
 autoFillBackground
 
 baseSize
 
 childrenRect
 
 childrenRegion
 
 contextMenuPolicy
 
 cursor
 
 enabled
 
 focus
 
 focusPolicy
 
 font
 
 frameGeometry
 
 frameSize
 
 fullScreen
 
 geometry
 
 height
 
 inputMethodHints
 
 isActiveWindow
 
 layoutDirection
 
 locale
 
 maximized
 
 maximumHeight
 
 maximumSize
 
 maximumWidth
 
 minimized
 
 minimumHeight
 
 minimumSize
 
 minimumSizeHint
 
 minimumWidth
 
 modal
 
 mouseTracking
 
 normalGeometry
 
 palette
 
 pos
 
 rect
 
 size
 
 sizeHint
 
 sizeIncrement
 
 sizePolicy
 
 statusTip
 
 styleSheet
 
 toolTip
 
 updatesEnabled
 
 visible
 
 whatsThis
 
 width
 
 windowFilePath
 
 windowFlags
 
 windowIcon
 
 windowIconText
 
 windowModality
 
 windowModified
 
 windowOpacity
 
 windowTitle
 
 x
 
 y
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Static Public Methods inherited from QWidget
static QWidget * createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
static QWidget * find (WId id)
 
static QWidget * keyboardGrabber ()
 
static QWidget * mouseGrabber ()
 
static void setTabOrder (QWidget *firstWidget, QWidget *secondWidget)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 

Detailed Description

The QMainWindow class provides the main GUI application window. This class and related classes are used to manage the components of the main window. QMainWindow has its own layout where QToolBars QDockWidget, QMenuBar, or a QStatusBar can be added. The layout has a center area which can be occupied by any kind of widget.

Creating a main window without a central widget is not supported. You must have a central widget even if it is just a placeholder.

Creating Main Window Components

A central widget will typically be a standard widget such as a QTextEdit or a QGraphicsView. Custom widgets can also be used. Main windows have either a single (SDI) or multiple (MDI) document interface. An MDI application is created using QMdiArea as the central widget.

The central widget is set using setCentralWidget().

Creating Menus

Menus are created using the QMenu class. QActions, which are the associated action to take when the menu item is selected, are added to each menu item. QMainWindow stores the appropriate information in a QMenuBar which is then responsible for displaying the menu items.

QMainWindow has a default menu bar which can be redefined by using setMenuBar(). In most cases this is not necessary. Normally new menu are added to the existing main window menu bar by calling menuBar()->addMenu().

The following is an example showing how to create a menu.

void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(newAct);
fileMenu->addAction(openAct);
fileMenu->addAction(saveAct);
}

The createPopupMenu() method is called when the main window receives a context menu event. The default implementation generates a pop up menu with the checkable actions from the dock widgets and toolbars. You can override createPopupMenu() to provide a custom menu.

Creating Toolbars

Toolbars are implemented in the QToolBar class. To add a toolbar to a main window call addToolBar().

The initial position of a toolbar is set by assigning it to a specific Qt::ToolBarArea. You can split an area by inserting a toolbar break with addToolBarBreak() or insertToolBarBreak(). You can also restrict placement by the user with QToolBar::setAllowedAreas() and QToolBar::setMovable().

The size of toolbar icons can be retrieved with iconSize(). The sizes are platform dependent. A fixed size can be set with setIconSize(). The appearance can be changed for all tool buttons in the toolbars with setToolButtonStyle().

The following is an example of how to create a new toolbar.

void MainWindow::createToolBars() {
fileToolBar = addToolBar(tr("File"));
fileToolBar->addAction(newAct);
}

Creating Dock Widgets

Dock widgets are implemented in the QDockWidget class. A dock widget is a window that can be docked into the main window. You add dock widgets to a main window with addDockWidget().

There are four dock widget areas as given by the Qt::DockWidgetArea enum: left, right, top, and bottom. You can specify which dock widget area that should occupy the corners where the areas overlap with setCorner(). By default each area can only contain one row (vertical or horizontal) of dock widgets, but if you enable nesting with setDockNestingEnabled(), dock widgets can be added in either direction.

Two dock widgets may also be stacked on top of each other. A QTabBar is then used to select which of the widgets that should be displayed.

The following is an example showing how to add dock widgets to a main window.

QDockWidget *dockWidget = new QDockWidget(tr("Dock Widget"), this);
dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
dockWidget->setWidget(dockWidgetContents);
addDockWidget(Qt::LeftDockWidgetArea, dockWidget);

The Status Bar

You can set a status bar with setStatusBar(), but one is created the first time statusBar() (which returns the main window's status bar) is called. See QStatusBar for information on how to use it.

Storing State

QMainWindow can store the state of its layout with saveState(); it can later be retrieved with restoreState(). It is the position and size (relative to the size of the main window) of the toolbars and dock widgets that are stored.

See also
QMenuBar, QToolBar, QStatusBar, QDockWidget

Member Typedef Documentation

Typedef for QFlags<DockOption>. Refer to QMainWindow::DockOption for documentation.

Member Enumeration Documentation

This enum contains flags that specify the docking behavior of QMainWindow.

These options only control how dock widgets may be dropped in a QMainWindow. They do not re-arrange the dock widgets to conform with the specified options. For this reason they should be set before any dock widgets are added to the main window. Exceptions to this are the AnimatedDocks and VerticalTabs options, which may be set at any time.

ConstantValueDescription
QMainWindow::AnimatedDocks0x01 Identical to the animated property.
QMainWindow::AllowNestedDocks0x02 Identical to the dockNestingEnabled property.
QMainWindow::AllowTabbedDocks0x04 The user can drop one dock widget "on top" of another. The two widgets are stacked and a tab bar appears for selecting which one is visible.
QMainWindow::ForceTabbedDocks0x08 Each dock area contains a single stack of tabbed dock widgets. In other words, dock widgets can not be placed next to each other in a dock area. If this option is set, AllowNestedDocks has no effect.
QMainWindow::VerticalTabs0x10 The two vertical dock areas on the sides of the main window show their tabs vertically. If this option is not set, all dock areas show their tabs at the bottom. Implies AllowTabbedDocks. Refer to setTabPosition().

Constructor & Destructor Documentation

QMainWindow::QMainWindow ( QWidget parent = nullptr,
Qt::WindowFlags  flags = Qt::EmptyFlag 
)
explicit

Constructs a QMainWindow with the given parent and the specified widget flags. QMainWindow sets the Qt::Window flag itself, and will hence always be created as a top-level widget.

QMainWindow::~QMainWindow ( )

Destroys the main window.

Method Documentation

void QMainWindow::addDockWidget ( Qt::DockWidgetArea  area,
QDockWidget dockwidget 
)

Adds the given dockwidget to the specified area.

void QMainWindow::addDockWidget ( Qt::DockWidgetArea  area,
QDockWidget dockwidget,
Qt::Orientation  orientation 
)

Adds dockwidget into the given area in the direction specified by the orientation.

QToolBar * QMainWindow::addToolBar ( const QString title)

Creates a QToolBar object, setting its window title to title, and inserts it into the top toolbar area.

See also
setWindowTitle()
void QMainWindow::addToolBar ( Qt::ToolBarArea  area,
QToolBar toolbar 
)

Adds the toolbar into the specified area in this main window. The toolbar is placed at the end of the current tool bar block (i.e. line). If the main window already manages toolbar then it will only move the toolbar to area.

See also
insertToolBar(), addToolBarBreak(), insertToolBarBreak()
void QMainWindow::addToolBar ( QToolBar toolbar)

Equivalent of calling addToolBar(Qt::TopToolBarArea, toolbar)

void QMainWindow::addToolBarBreak ( Qt::ToolBarArea  area = Qt::TopToolBarArea)

Adds a toolbar break to the given area after all the other objects that are present.

QWidget * QMainWindow::centralWidget ( ) const

Returns the central widget for the main window. This method returns a nullptr if the central widget has not been set.

See also
setCentralWidget()
void QMainWindow::contextMenuEvent ( QContextMenuEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::contextMenuEvent().

Reimplemented from QWidget.

Qt::DockWidgetArea QMainWindow::corner ( Qt::Corner  corner) const

Returns the dock widget area that occupies the specified corner.

See also
setCorner()
QMenu * QMainWindow::createPopupMenu ( )
virtual

Returns a popup menu containing checkable entries for the toolbars and dock widgets present in the main window. If there are no toolbars and dock widgets present, this function returns a null pointer.

By default this method is called by the main window when the user activates a context menu, typically by right-clicking on a toolbar or a dock widget.

If you want to create a custom popup menu, reimplement this function and return a newly created popup menu. Ownership of the popup menu is transferred to the caller.

See also
addDockWidget(), addToolBar(), menuBar()
DockOptions QMainWindow::dockOptions ( ) const

Property documentation pending

Qt::DockWidgetArea QMainWindow::dockWidgetArea ( QDockWidget dockwidget) const

Returns the Qt::DockWidgetArea for dockwidget. If dockwidget has not been added to the main window, this function returns Qt::NoDockWidgetArea.

See also
addDockWidget(), splitDockWidget(), Qt::DockWidgetArea
bool QMainWindow::documentMode ( ) const

Property documentation pending.

bool QMainWindow::event ( QEvent event)
overrideprotected

Reimplemented from QObject::event().

QSize QMainWindow::iconSize ( ) const

Property documentation pending.

void QMainWindow::iconSizeChanged ( const QSize iconSize)
signal

This signal is emitted when the size of the icons used in the window is changed. The new icon size is passed in iconSize.

You can connect this signal to other components to help maintain a consistent appearance for your application.

See also
setIconSize()
void QMainWindow::insertToolBar ( QToolBar before,
QToolBar toolbar 
)

Inserts the toolbar into the area occupied by the before toolbar so that it appears before it. For example, in normal left-to-right layout operation, this means that toolbar will appear to the left of the toolbar specified by before in a horizontal toolbar area.

See also
insertToolBarBreak(), addToolBar(), addToolBarBreak()
void QMainWindow::insertToolBarBreak ( QToolBar before)

Inserts a toolbar break before the toolbar specified by before.

bool QMainWindow::isAnimated ( ) const

Property documentation pending.

bool QMainWindow::isDockNestingEnabled ( ) const

Property documentation pending.

QMenuBar * QMainWindow::menuBar ( ) const

Returns the menu bar for the main window. This function creates and returns an empty menu bar if the menu bar does not exist.

If you want all windows in a Mac application to share one menu bar, do not use this function to create it, because the menu bar created here will have this QMainWindow as its parent. Instead, you must create a menu bar that does not have a parent, which you can then share among all the Mac windows. Create a parent-less menu bar this way:

See also
setMenuBar()
QWidget * QMainWindow::menuWidget ( ) const

Returns the menu bar for the main window. This function returns null if a menu bar has not been constructed yet.

See also
setMenuWidget()
void QMainWindow::removeDockWidget ( QDockWidget dockwidget)

Removes the dockwidget from the main window layout and hides it. Note that the dockwidget is not deleted.

void QMainWindow::removeToolBar ( QToolBar toolbar)

Removes the toolbar from the main window layout and hides it. Note that the toolbar is not deleted.

void QMainWindow::removeToolBarBreak ( QToolBar before)

Removes a toolbar break previously inserted before the toolbar specified by before.

void QMainWindow::resizeDocks ( const QList< QDockWidget * > &  docks,
const QList< int > &  sizes,
Qt::Orientation  orientation 
)

Resizes the dock widgets in the list docks to the corresponding size in pixels from the list sizes. If orientation is Qt::Horizontal, adjusts the width, otherwise adjusts the height of the dock widgets. The sizes will be adjusted such that the maximum and the minimum sizes are respected and the QMainWindow itself will not be resized. Any additional/missing space is distributed amongst the widgets according to the relative weight of the sizes.

resizeDocks({blueWidget, yellowWidget}, {20 , 40}, Qt::Horizontal);

If the blue and the yellow widget are nested on the same level they will be resized such that the yellowWidget is twice as big as the blueWidget. If some widgets are grouped in tabs, only one widget per group should be specified. Widgets not in the list might be changed to respect the constraints.

bool QMainWindow::restoreDockWidget ( QDockWidget dockwidget)

Restores the state of dockwidget if it is created after the call to restoreState(). Returns true if the state was restored, otherwise returns false.

See also
restoreState(), saveState()
bool QMainWindow::restoreState ( const QByteArray state,
int  version = 0 
)

Restores the state of this mainwindow's toolbars and dockwidgets. The version number is compared with that stored in state. If they do not match the mainwindow's state is left unchanged and this method returns false. Otherwise the state is restored and this method returns true.

To restore geometry saved using QSettings, you can use code like this:

void MainWindow::readSettings()
{
QSettings settings("MyCompany", "MyApp");
restoreGeometry(settings.value("myWidget/geometry").toByteArray());
restoreState(settings.value("myWidget/windowState").toByteArray());
}
See also
saveState(), QWidget::saveGeometry(), QWidget::restoreGeometry(), restoreDockWidget()
QByteArray QMainWindow::saveState ( int  version = 0) const

Saves the current state of this mainwindow's toolbars and dockwidgets. The version number is stored as part of the data. The objectName property is used to identify each QToolBar and QDockWidget. You should make sure that this property is unique for each QToolBar and QDockWidget you add to the QMainWindow.

To restore the saved state, pass the return value and version number to restoreState(). To save the geometry when the window closes you can implement a close event as shown below.

void MyMainWindow::closeEvent(QCloseEvent *event) {
QSettings settings("MyCompany", "MyApp");
settings.setValue("geometry", saveGeometry());
settings.setValue("windowState", saveState());
}
See also
restoreState(), QWidget::saveGeometry(), QWidget::restoreGeometry()
void QMainWindow::setAnimated ( bool  enabled)
slot

Property documentation pending.

void QMainWindow::setCentralWidget ( QWidget widget)

Sets the given widget to be the main window's central widget. QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.

See also
centralWidget()
void QMainWindow::setCorner ( Qt::Corner  corner,
Qt::DockWidgetArea  area 
)

Sets the given dock widget area to occupy the specified corner.

See also
corner()
void QMainWindow::setDockNestingEnabled ( bool  enabled)
slot

Property documentation pending.

void QMainWindow::setDockOptions ( DockOptions  options)

Property documentation pending

void QMainWindow::setDocumentMode ( bool  enabled)

Property documentation pending.

void QMainWindow::setIconSize ( const QSize iconSize)

Property documentation pending.

void QMainWindow::setMenuBar ( QMenuBar menuBar)

Sets the menu bar for the main window to menuBar. QMainWindow takes ownership of the menuBar pointer and deletes it at the appropriate time.

See also
menuBar()
void QMainWindow::setMenuWidget ( QWidget menuBar)

Sets the menu bar for the main window to menuBar. QMainWindow takes ownership of the menuBar pointer and deletes it at the appropriate time.

See also
menuWidget()
void QMainWindow::setStatusBar ( QStatusBar statusbar)

Sets the status bar for the main window to statusbar. Setting the status bar to nullptr will remove it from the main window. QMainWindow takes ownership of the statusbar pointer and deletes it at the appropriate time.

See also
statusBar()
void QMainWindow::setTabPosition ( Qt::DockWidgetAreas  areas,
QTabWidget::TabPosition  tabPosition 
)

Sets the tab position for the given dock widget areas to the specified tabPosition. By default all dock areas show their tabs at the bottom.

Note
The VerticalTabs dock option overrides the tab positions set by this method.
See also
tabPosition(), setTabShape()
void QMainWindow::setTabShape ( QTabWidget::TabShape  tabShape)

Property documentation pending.

void QMainWindow::setToolButtonStyle ( Qt::ToolButtonStyle  toolButtonStyle)

Property documentation pending

void QMainWindow::setUnifiedTitleAndToolBarOnMac ( bool  set)
slot

Property documentation pending.

void QMainWindow::splitDockWidget ( QDockWidget first,
QDockWidget second,
Qt::Orientation  orientation 
)

Splits the space covered by the first dock widget into two parts, moves the first dock widget into the first part, and moves the second dock widget into the second part.

The orientation specifies how the space is divided: A Qt::Horizontal split places the second dock widget to the right of the first; a Qt::Vertical split places the second dock widget below the first.

If first is currently in a tabbed docked area, second will be added as a new tab, not as a neighbor of first. This is because a single tab can contain only one dock widget.

The Qt::LayoutDirection influences the order of the dock widgets in the two parts of the divided area. When right-to-left layout direction is enabled, the placing of the dock widgets will be reversed.

See also
tabifyDockWidget(), addDockWidget(), removeDockWidget()
QStatusBar * QMainWindow::statusBar ( ) const

Returns the status bar for the main window. This function creates and returns an empty status bar if the status bar does not exist.

See also
setStatusBar()
QList< QDockWidget * > QMainWindow::tabifiedDockWidgets ( QDockWidget dockwidget) const

Returns the dock widgets that are tabified together with dockwidget.

See also
tabifyDockWidget()
void QMainWindow::tabifyDockWidget ( QDockWidget first,
QDockWidget second 
)

Moves second dock widget on top of first dock widget, creating a tabbed docked area in the main window.

See also
tabifiedDockWidgets()
QTabWidget::TabPosition QMainWindow::tabPosition ( Qt::DockWidgetArea  area) const

Returns the tab position for area.

Note
The VerticalTabs dock option overrides the tab positions returned by this function.
See also
setTabPosition(), tabShape()
QTabWidget::TabShape QMainWindow::tabShape ( ) const

Property documentation pending.

QWidget * QMainWindow::takeCentralWidget ( )

Removes the central widget from this main window. The ownership of the removed widget is passed to the caller.

Qt::ToolBarArea QMainWindow::toolBarArea ( QToolBar toolbar) const

Returns the Qt::ToolBarArea for toolbar. If toolbar has not been added to the main window, this function returns Qt::NoToolBarArea.

See also
addToolBar(), addToolBarBreak(), Qt::ToolBarArea
bool QMainWindow::toolBarBreak ( QToolBar toolbar) const

Returns whether there is a toolbar break before the toolbar.

See also
addToolBarBreak(), insertToolBarBreak()
Qt::ToolButtonStyle QMainWindow::toolButtonStyle ( ) const

Property documentation pending.

void QMainWindow::toolButtonStyleChanged ( Qt::ToolButtonStyle  toolButtonStyle)
signal

This signal is emitted when the style used for tool buttons in the window is changed. The new style is passed in toolButtonStyle.

You can connect this signal to other components to help maintain a consistent appearance for your application.

See also
setToolButtonStyle()
bool QMainWindow::unifiedTitleAndToolBarOnMac ( ) const

Property documentation pending.

Property Documentation

QMainWindow::animated

This property holds whether manipulating dock widgets and tool bars is animated.

When a dock widget or tool bar is dragged over the main window, the main window adjusts its contents to indicate where the dock widget or tool bar will be docked if it is dropped. Setting this property causes QMainWindow to move its contents in a smooth animation. Clearing this property causes the contents to snap into their new positions.

By default, this property is set. It may be cleared if the main window contains widgets which are slow at resizing or repainting themselves.

Setting this property is identical to setting the AnimatedDocks option using setDockOptions().

PropertiesClass Methods
read isAnimated
write setAnimated
QMainWindow::dockNestingEnabled

This property holds whether docks can be nested.

If this property is false, dock areas can only contain a single row (horizontal or vertical) of dock widgets. If this property is true, the area occupied by a dock widget can be split in either direction to contain more dock widgets.

Dock nesting is only necessary in applications that contain a lot of dock widgets. It gives the user greater freedom in organizing their main window. However, dock nesting leads to more complex (and less intuitive) behavior when a dock widget is dragged over the main window, since there are more ways in which a dropped dock widget may be placed in the dock area.

Setting this property is identical to setting the AllowNestedDocks option using setDockOptions().

PropertiesClass Methods
read isDockNestingEnabled
write setDockNestingEnabled
QMainWindow::dockOptions

This property holds the docking behavior of QMainWindow. The default value is AnimatedDocks | AllowTabbedDocks.

PropertiesClass Methods
read dockOptions
write setDockOptions
QMainWindow::documentMode

This property holds whether the tab bar for tabbed dockwidgets is set to document mode. The default is false.

See also
QTabBar::documentMode
PropertiesClass Methods
read documentMode
write setDocumentMode
QMainWindow::iconSize

This property holds size of toolbar icons in this mainwindow. The default is the default tool bar icon size of the GUI style. The icons used must be at least of this size as the icons are only scaled down.

PropertiesClass Methods
read iconSize
write setIconSize
QMainWindow::tabShape

This property holds the tab shape used for tabbed dock widgets. The default is QTabWidget::Rounded.

See also
setTabPosition()
PropertiesClass Methods
read tabShape
write setTabShape
QMainWindow::toolButtonStyle

This property holds style of toolbar buttons in this mainwindow. The default is Qt::ToolButtonIconOnly.

PropertiesClass Methods
read toolButtonStyle
write setToolButtonStyle
QMainWindow::unifiedTitleAndToolBarOnMac

This property holds whether the window uses the unified title and toolbar look on Mac OS X. This property is false by default and only has any effect on Mac OS X 10.4 or higher.

If set to true, then the top toolbar area is replaced with a Carbon HIToolbar or a Cocoa NSToolbar (depending on whether CopperSpice was built with Carbon or Cocoa). All toolbars in the top toolbar area and any toolbars added afterwards are moved to that. This means a couple of things.

  • QToolBars in this toolbar area are not movable and you can not drag other toolbars to it
  • Toolbar breaks are not respected or preserved
  • Any custom widgets in the toolbar will not be shown if the toolbar becomes too small (only actions will be shown)

Setting this back to false will remove these restrictions.

The Qt::WA_MacBrushedMetal attribute takes precedence over this property.

PropertiesClass Methods
read unifiedTitleAndToolBarOnMac
write setUnifiedTitleAndToolBarOnMac