CopperSpice API  1.9.1
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 Typedefs inherited from QWidget
using RenderFlags = QFlags< RenderFlag >
 

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 *location, QToolBar *newToolbar)
 
void insertToolBarBreak (QToolBar *location)
 
bool isAnimated () const
 
bool isDockNestingEnabled () const
 
QMenuBarmenuBar () const
 
QWidgetmenuWidget () const
 
void removeDockWidget (QDockWidget *dockwidget)
 
void removeToolBar (QToolBar *toolbar)
 
void removeToolBarBreak (QToolBar *location)
 
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 &childName=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)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
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, commonly referred to as simply the "main window". This class manages it own internal layout structure which supports adding objects like a QMenuBar, QToolBar, QStatusBar, or a QDockWidget. The layout has a center area which can be occupied by any kind of widget.

Central Widget

A main window must contain a central widget.

The central widget can be any class which inherits from QWidget. Common choices include QWidget itset, QTextEdit, or a QGraphicsView. Custom widgets can also be used. A central widget is added to a main window by calling setCentralWidget().

Menus

Menus can be displayed on a main window. The horizontal area at the top is called the menu bar and is created by the QMenuBar class. The sub-menu items are created by they QMenu class. The QMainWindow class has a default QMenuBar object which can be retrieved by calling QMainWindow::menuBar().

To create a new entry on the menu bar call menuBar()->addMenu() and pass the name of the menu item. This method returns a pointer which can then be used to add a QAction to the menu. The action is a pointer to an object which can set the icon, tool tip, and declare signal/slot connection indicating what should happen then the menu item is selected.

The following is an example which shows how to create the actions, a menu bar, and menu items.

void MainWindow::createMenus()
{
QAction *openFile = new QAction(tr("Open"));
QAction *closeFile = new QAction(tr("Close"));
QAction *saveFile = new QAction(tr("Save"));
//
QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(openFile);
fileMenu->addAction(saveFile);
fileMenu->addAction(printFile);
}

As an alternative, the QMainWindow default menu bar can be redefined by using the method setMenuBar().

Toolbars

A toolbar can be added to a main window by calling the method QMainWindow::addToolBar(). This method returns a pointer to a new QToolBar object. Normally the same action created for the menu is used for toolbar items. The following is an example showing how to create a new toolbar.

void MainWindow::createToolBars()
{
QAction *openFile = new QAction(tr("Open"));
QToolBar *fileToolBar = addToolBar(tr("File"));
fileToolBar->addAction(openFile);
}

The toolbar display can be adjusted by using the methods QMainWindow::addToolBarBreak(), QMainWindow::insertToolBarBreak(), QToolBar::setAllowedAreas(), and QToolBar::setMovable().

Dock Widgets

A dock widget is a window which can be docked on the edge of the main window or floating on the user's desktop. They are added to a main window by calling QMainWindow::addDockWidget(). Dock widgets are created by the QDockWidget class.

There are four dock widget areas defined by the Qt::DockWidgetArea enum: left, right, top, and bottom. By default each dock widget area can only contain one vertical or horizontal row of dock widgets. Multiple dock widgets can be stacked on top of each other. A QTabBar is automatically added to show one of the dock widgets at a time.

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);

Status Bar

You can set a status bar by calling setStatusBar(). If you do not set this then one will automatically be created the first time statusBar() is called.

Storing State

QMainWindow can store the state of its layout with saveState(). It can later be retrieved with restoreState(). The state contains the position and size of toolbars and dock widgets, relative to the size of the main window.

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 in the specified area on this main window. The new toolbar is placed after any existing toolbar. If this toolbar has already been added to the current QMainWindow, the given toolbar will be moved to the specified area.

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

Equivalent to 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()

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

This 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. If there are no toolbars and dock widgets present, this method returns a null pointer.

If you want to create a custom popup menu reimplement this method 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

Returns the value of the property.

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

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

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

Returns the value of the property.

bool QMainWindow::event ( QEvent event)
overrideprotected

Reimplemented from QWidget::event()

QSize QMainWindow::iconSize ( ) const

Returns the value of the property.

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. This signal can be connected to other components to help maintain a consistent appearance for your application.

See also
setIconSize()
void QMainWindow::insertToolBar ( QToolBar location,
QToolBar newToolbar 
)

Inserts the newToolbar at the given location in the existing toolbar.

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

Inserts a toolbar break before the toolbar specified by the given location.

bool QMainWindow::isAnimated ( ) const

Returns the value of the property.

bool QMainWindow::isDockNestingEnabled ( ) const

Returns the value of the property.

QMenuBar * QMainWindow::menuBar ( ) const

Returns the menu bar for the main window. This method creates an empty menu bar if the menu bar does not exist and then returns a pointer to the new menu bar.

If you want every window in a Mac OS X application to share one menu bar, do not use this method. The menu bar it creates will have this QMainWindow as its parent. Instead, create a menu bar without a parent which can be shared among all the windows.

QMenuBar *menuBar = new QMenuBar(nullptr);
See also
setMenuBar()
QWidget * QMainWindow::menuWidget ( ) const

Returns the menu bar for the main window. This method returns a nullptr if a menu bar has not been constructed.

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 location)

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

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.

The following is an example showing how to restore geometry saved using QSettings.

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

Sets the value of the property to enabled.

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

Sets the value of the property to enabled.

void QMainWindow::setDockOptions ( DockOptions  options)

Sets the value of the property to options.

void QMainWindow::setDocumentMode ( bool  enabled)

Sets the value of the property to enabled.

void QMainWindow::setIconSize ( const QSize iconSize)

Sets the value of the property to iconSize.

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)

Sets the value of the property to tabShape.

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

Sets the value of the property to toolButtonStyle.

void QMainWindow::setUnifiedTitleAndToolBarOnMac ( bool  set)
slot

Sets the value of the property to set.

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

Splits the space covered by the dock widget into two parts. It moves the first dock widget into the first part and moves the second dock widget into the second part. If first is currently in a tab then second will be added as a new tab since a single tab can only contain one dock widget.

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. 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 method 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 method.
See also
setTabPosition(), tabShape()
QTabWidget::TabShape QMainWindow::tabShape ( ) const

Returns the value of the property.

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 method 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

Returns the value of the property.

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

Returns the value of the property.

Property Documentation

QMainWindow::animated

This property holds whether manipulating dock widgets and toolbars is animated.

When a dock widget or toolbar is dragged over the main window, the main window adjusts its contents to indicate where the dock widget or toolbar 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 the size of toolbar icons displayed on this QMainWindow. The default size is the toolbar icon size from the current GUI style. The size of the supplied icons should not be smaller than the value of this property.

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