Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Functions | Properties | List of all members
QMainWindow Class Reference

The QMainWindow class provides a main application window. More...

#include <qmainwindow.h>

Inheritance diagram for QMainWindow:
QWidget QObject QPaintDevice

Public Types

enum  DockOption {
  AnimatedDocks = 0x01, AllowNestedDocks = 0x02, AllowTabbedDocks = 0x04, ForceTabbedDocks = 0x08,
  VerticalTabs = 0x10
}
 This enum contains flags that specify the docking behavior of QMainWindow. More...
 
- Public Types inherited from QWidget
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
 This enum describes how to render the widget when calling QWidget::render(). More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 

Public Slots

void setAnimated (bool enabled)
 
void setDockNestingEnabled (bool enabled)
 
- Public Slots inherited from QWidget
bool close ()
 Closes this widget. More...
 
void hide ()
 Hides the widget. More...
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack. More...
 
void raise ()
 Raises this widget to the top of the parent widget's stack. More...
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden. More...
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events. More...
 
void setEnabled (bool)
 
void setFocus ()
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden). More...
 
QT_MOC_COMPAT void setShown (bool shown)
 Use setVisible(shown) instead. More...
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void show ()
 Shows the widget and its child widgets. More...
 
void showFullScreen ()
 Shows the widget in full-screen mode. More...
 
void showMaximized ()
 Shows the widget maximized. More...
 
void showMinimized ()
 Shows the widget minimized, as an icon. More...
 
void showNormal ()
 Restores the widget after it has been maximized or minimized. More...
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void iconSizeChanged (const QSize &iconSize)
 This signal is emitted when the size of the icons used in the window is changed. More...
 
void toolButtonStyleChanged (Qt::ToolButtonStyle toolButtonStyle)
 This signal is emitted when the style used for tool buttons in the window is changed. More...
 
- Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void addDockWidget (Qt::DockWidgetArea area, QDockWidget *dockwidget)
 Adds the given dockwidget to the specified area. More...
 
void addDockWidget (Qt::DockWidgetArea area, QDockWidget *dockwidget, Qt::Orientation orientation)
 Adds dockwidget into the given area in the direction specified by the orientation. More...
 
void addToolBar (Qt::ToolBarArea area, QToolBar *toolbar)
 Adds the toolbar into the specified area in this main window. More...
 
void addToolBar (QToolBar *toolbar)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Equivalent of calling addToolBar(Qt::TopToolBarArea, toolbar) More...
 
QToolBaraddToolBar (const QString &title)
 Creates a QToolBar object, setting its window title to title, and inserts it into the top toolbar area. More...
 
void addToolBarBreak (Qt::ToolBarArea area=Qt::TopToolBarArea)
 Adds a toolbar break to the given area after all the other objects that are present. More...
 
QWidgetcentralWidget () const
 Returns the central widget for the main window. More...
 
Qt::DockWidgetArea corner (Qt::Corner corner) const
 Returns the dock widget area that occupies the specified corner. More...
 
virtual QMenucreatePopupMenu ()
 Returns a popup menu containing checkable entries for the toolbars and dock widgets present in the main window. More...
 
DockOptions dockOptions () const
 
Qt::DockWidgetArea dockWidgetArea (QDockWidget *dockwidget) const
 Returns the Qt::DockWidgetArea for dockwidget. More...
 
bool documentMode () const
 
QSize iconSize () const
 
void insertToolBar (QToolBar *before, QToolBar *toolbar)
 Inserts the toolbar into the area occupied by the before toolbar so that it appears before it. More...
 
void insertToolBarBreak (QToolBar *before)
 Inserts a toolbar break before the toolbar specified by before. More...
 
bool isAnimated () const
 
bool isDockNestingEnabled () const
 
bool isSeparator (const QPoint &pos) const
 
QMenuBarmenuBar () const
 Returns the menu bar for the main window. More...
 
QWidgetmenuWidget () const
 Returns the menu bar for the main window. More...
 
 QMainWindow (QWidget *parent=0, Qt::WindowFlags flags=0)
 Constructs a QMainWindow with the given parent and the specified widget flags. More...
 
void removeDockWidget (QDockWidget *dockwidget)
 Removes the dockwidget from the main window layout and hides it. More...
 
void removeToolBar (QToolBar *toolbar)
 Removes the toolbar from the main window layout and hides it. More...
 
void removeToolBarBreak (QToolBar *before)
 Removes a toolbar break previously inserted before the toolbar specified by before. More...
 
bool restoreDockWidget (QDockWidget *dockwidget)
 Restores the state of dockwidget if it is created after the call to restoreState(). More...
 
bool restoreState (const QByteArray &state, int version=0)
 Restores the state of this mainwindow's toolbars and dockwidgets. More...
 
QByteArray saveState (int version=0) const
 Saves the current state of this mainwindow's toolbars and dockwidgets. More...
 
void setCentralWidget (QWidget *widget)
 Sets the given widget to be the main window's central widget. More...
 
void setCorner (Qt::Corner corner, Qt::DockWidgetArea area)
 Sets the given dock widget area to occupy the specified corner. More...
 
void setDockOptions (DockOptions options)
 
void setDocumentMode (bool enabled)
 
void setIconSize (const QSize &iconSize)
 
void setMenuBar (QMenuBar *menubar)
 Sets the menu bar for the main window to menuBar. More...
 
void setMenuWidget (QWidget *menubar)
 Sets the menu bar for the main window to menuBar. More...
 
void setStatusBar (QStatusBar *statusbar)
 Sets the status bar for the main window to statusbar. More...
 
void setTabPosition (Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition)
 Sets the tab position for the given dock widget areas to the specified tabPosition. More...
 
void setTabShape (QTabWidget::TabShape tabShape)
 
void setToolButtonStyle (Qt::ToolButtonStyle toolButtonStyle)
 
void setUnifiedTitleAndToolBarOnMac (bool set)
 
void splitDockWidget (QDockWidget *after, QDockWidget *dockwidget, 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. More...
 
QStatusBarstatusBar () const
 Returns the status bar for the main window. More...
 
QList< QDockWidget * > tabifiedDockWidgets (QDockWidget *dockwidget) const
 Returns the dock widgets that are tabified together with dockwidget. More...
 
void tabifyDockWidget (QDockWidget *first, QDockWidget *second)
 Moves second dock widget on top of first dock widget, creating a tabbed docked area in the main window. More...
 
QTabWidget::TabPosition tabPosition (Qt::DockWidgetArea area) const
 Returns the tab position for area. More...
 
QTabWidget::TabShape tabShape () const
 
Qt::ToolBarArea toolBarArea (QToolBar *toolbar) const
 Returns the Qt::ToolBarArea for toolbar. More...
 
bool toolBarBreak (QToolBar *toolbar) const
 Returns whether there is a toolbar break before the toolbar. More...
 
Qt::ToolButtonStyle toolButtonStyle () const
 
bool unifiedTitleAndToolBarOnMac () const
 
 ~QMainWindow ()
 Destroys the main window. More...
 
- Public Functions inherited from QWidget
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions. More...
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window. More...
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions. More...
 
void addActions (QList< QAction *> actions)
 Appends the actions actions to this widget's list of actions. More...
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents. More...
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget. More...
 
QSize baseSize () const
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system. More...
 
QWidgetchildAt (const QPoint &p) const
 Returns the visible child widget at point p in the widget's own coordinate system. More...
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 Takes keyboard input focus from the widget. More...
 
void clearMask ()
 Removes any mask set by setMask(). More...
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins. More...
 
QRect contentsRect () const
 Returns the area inside the widget's margins. More...
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void createWinId ()
 
QCursor cursor () const
 
int devType () const
 
WId effectiveWinId () const
 Returns the effective window system identifier of the widget, i. More...
 
void ensurePolished () const
 Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette). More...
 
Qt::FocusPolicy focusPolicy () const
 
QWidgetfocusProxy () const
 Returns the focus proxy, or 0 if there is no focus proxy. More...
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on. More...
 
const QFontfont () const
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font. More...
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font. More...
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role. More...
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 Returns the widget's contents margins for left, top, right, and bottom. More...
 
HDC getDC () const
 Returns the window system handle of the widget, for low-level access. More...
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
void grabMouse (const QCursor &)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. More...
 
QGraphicsEffectgraphicsEffect () const
 The graphicsEffect function returns a pointer to the widget's graphics effect. More...
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0. More...
 
bool hasFocus () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int) const
 Returns the preferred height for this widget, given the width w. More...
 
QInputContextinputContext ()
 This function returns the QInputContext for this widget. More...
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery) const
 This method is only relevant for input widgets. More...
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before. More...
 
void insertActions (QAction *before, QList< QAction *> actions)
 Inserts the actions actions to this widget's list of actions, before the action before. More...
 
WId internalWinId () const
 Returns the window system identifier of the widget, or 0 if the widget is not created yet. More...
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child, and both widgets are within the same window; otherwise returns false. More...
 
bool isEnabled () const
 
bool isEnabledTo (QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false. More...
 
bool isEnabledToTLW () const
 This function is deprecated. More...
 
bool isFullScreen () const
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false. More...
 
bool isLeftToRight () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isRightToLeft () const
 
bool isTopLevel () const
 Use isWindow() instead. More...
 
bool isVisible () const
 
bool isVisibleTo (QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false. More...
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false. More...
 
bool isWindowModified () const
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed. More...
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
Qt::HANDLE macCGHandle () const
 Returns the CoreGraphics handle of the widget. More...
 
Qt::HANDLE macQDHandle () const
 Returns the QuickDraw handle of the widget. More...
 
QPoint mapFrom (QWidget *, const QPoint &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system. More...
 
QPoint mapFromGlobal (const QPoint &) const
 Translates the global screen coordinate pos to widget coordinates. More...
 
QPoint mapFromParent (const QPoint &) const
 Translates the parent widget coordinate pos to widget coordinates. More...
 
QPoint mapTo (QWidget *, const QPoint &) const
 Translates the widget coordinate pos to the coordinate system of parent. More...
 
QPoint mapToGlobal (const QPoint &) const
 Translates the widget coordinate pos to global screen coordinates. More...
 
QPoint mapToParent (const QPoint &) const
 Translates the widget coordinate pos to a coordinate in the parent widget. More...
 
QRegion mask () const
 Returns the mask currently set on a widget. More...
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
virtual QSize minimumSizeHint () const
 
int minimumWidth () const
 
void move (int x, int y)
 This corresponds to move(QPoint(x, y)). More...
 
void move (const QPoint &)
 
QWidgetnativeParentWidget () const
 Returns the native parent for this widget, i. More...
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain. More...
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system. More...
 
void overrideWindowState (Qt::WindowStates state)
 
QPaintEnginepaintEngine () const
 Returns the widget's paint engine. More...
 
const QPalettepalette () const
 
QWidgetparentWidget () const
 Returns the parent of this widget, or 0 if it does not have any parent widget. More...
 
QPoint pos () const
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain. More...
 
 QWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a widget which is a child of parent, with widget flags set to f. More...
 
QRect rect () const
 
void releaseDC (HDC) const
 Releases the HDC hdc acquired by a previous call to getDC(). More...
 
void releaseKeyboard ()
 Releases the keyboard grab. More...
 
void releaseMouse ()
 Releases the mouse grab. More...
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system. More...
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions. More...
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the sourceRegion of this widget into the target using renderFlags to determine how to render. More...
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the widget into the painter's QPainter::device(). More...
 
void repaint (int x, int y, int w, int h)
 This version repaints a rectangle (x, y, w, h) inside the widget. More...
 
void repaint (const QRect &)
 This version repaints a rectangle rect inside the widget. More...
 
void repaint (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void resize (int w, int h)
 This corresponds to resize(QSize(w, h)). More...
 
void resize (const QSize &)
 
bool restoreGeometry (const QByteArray &geometry)
 Restores the geometry and state top-level widgets stored in the byte array geometry. More...
 
QByteArray saveGeometry () const
 Saves the current geometry and state for top-level widgets. More...
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward. More...
 
void scroll (int dx, int dy, const QRect &)
 This version only scrolls r and does not move the children of the widget. More...
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. More...
 
void setAutoFillBackground (bool enabled)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role. More...
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 This corresponds to setBaseSize(QSize(basew, baseh)). More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom. More...
 
void setContentsMargins (const QMargins &margins)
 The setContentsMargins function sets the margins around the widget's contents. More...
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &)
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths. More...
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking. More...
 
void setFixedSize (int w, int h)
 Sets the width of the widget to w and the height to h. More...
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights. More...
 
void setFocus (Qt::FocusReason reason)
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w. More...
 
void setFont (const QFont &)
 Use the single-argument overload instead. More...
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role. More...
 
void setGeometry (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setGeometry(QRect(x, y, w, h)). More...
 
void setGeometry (const QRect &)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 The setGraphicsEffect function is for setting the widget's graphics effect. More...
 
void setInputContext (QInputContext *)
 This function sets the input context context on this widget. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. More...
 
void setMask (const QRegion &)
 Causes only the parts of the widget which overlap region to be visible. More...
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This function corresponds to setMaximumSize(QSize(maxw, maxh)). More...
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This function corresponds to setMinimumSize(QSize(minw, minh)). More...
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &)
 Use the single-argument overload instead. More...
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags. More...
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This function also takes widget flags, f as an argument. More...
 
void setShortcutAutoRepeat (int id, bool enable=true)
 If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled. More...
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled. More...
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 Sets the x (width) size increment to w and the y (height) size increment to h. More...
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width. More...
 
void setStatusTip (const QString &)
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style. More...
 
void setToolTip (const QString &)
 
void setUpdatesEnabled (bool enable)
 
void setupUi (QWidget *widget)
 Sets up the user interface for the specified widget. More...
 
void setWhatsThis (const QString &)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags type)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowIconText (const QString &)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &)
 Sets the window's role to role. More...
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState. More...
 
void setWindowSurface (QWindowSurface *surface)
 Sets the window surface to be the surface specified. More...
 
QSize size () const
 
virtual QSize sizeHint () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack. More...
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false. More...
 
QString toolTip () const
 
QWidgettopLevelWidget () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false. More...
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type. More...
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (int x, int y, int w, int h)
 This version updates a rectangle (x, y, w, h) inside the widget. More...
 
void update (const QRect &)
 This version updates a rectangle rect inside the widget. More...
 
void update (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry. More...
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur. More...
 
QString whatsThis () const
 
int width () const
 
QWidgetwindow () const
 Returns the window for this widget, i.e. More...
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e. More...
 
QIcon windowIcon () const
 
QString windowIconText () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 Returns the window's role, or an empty string. More...
 
Qt::WindowStates windowState () const
 Returns the current window state. More...
 
QWindowSurfacewindowSurface () const
 Returns the QWindowSurface this widget will be drawn into. More...
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 Returns the window type of this widget. More...
 
WId winId () const
 Returns the window system identifier of the widget. More...
 
int x () const
 
const QX11Infox11Info () const
 Returns information about the configuration of the X display used to display the widget. More...
 
Qt::HANDLE x11PictureHandle () const
 Returns the X11 Picture handle of the widget for XRender support. More...
 
int y () const
 
 ~QWidget ()
 Destroys the widget. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Protected Functions

void contextMenuEvent (QContextMenuEvent *event)
 Reimplemented Function More...
 
bool event (QEvent *event)
 Reimplemented Function More...
 
- Protected Functions inherited from QWidget
virtual void actionEvent (QActionEvent *)
 This event handler is called with the given event whenever the widget's actions are changed. More...
 
virtual void changeEvent (QEvent *)
 This event handler can be reimplemented to handle state changes. More...
 
virtual void closeEvent (QCloseEvent *)
 This event handler is called with the given event when Qt receives a window close request for a top-level widget from the window system. More...
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window if window is 0, otherwise sets the widget's window to window. More...
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources. More...
 
virtual void dragEnterEvent (QDragEnterEvent *)
 This event handler is called when a drag is in progress and the mouse enters this widget. More...
 
virtual void dragLeaveEvent (QDragLeaveEvent *)
 This event handler is called when a drag is in progress and the mouse leaves this widget. More...
 
virtual void dragMoveEvent (QDragMoveEvent *)
 This event handler is called if a drag is in progress, and when any of the following conditions occur: the cursor enters this widget, the cursor moves within this widget, or a modifier key is pressed on the keyboard while this widget has the focus. More...
 
virtual void dropEvent (QDropEvent *)
 This event handler is called when the drag is dropped on this widget. More...
 
virtual void enabledChange (bool)
 
virtual void enterEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter. More...
 
virtual void focusInEvent (QFocusEvent *)
 This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget. More...
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual bool focusNextPrevChild (bool next)
 Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void focusOutEvent (QFocusEvent *)
 This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget. More...
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void fontChange (const QFont &)
 
virtual void hideEvent (QHideEvent *)
 This event handler can be reimplemented in a subclass to receive widget hide events. More...
 
virtual void inputMethodEvent (QInputMethodEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive Input Method composition events. More...
 
virtual void keyPressEvent (QKeyEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive key press events for the widget. More...
 
virtual void keyReleaseEvent (QKeyEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive key release events for the widget. More...
 
virtual void languageChange ()
 
virtual void leaveEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter. More...
 
virtual bool macEvent (EventHandlerCallRef, EventRef)
 This special event handler can be reimplemented in a subclass to receive native Macintosh events. More...
 
int metric (PaintDeviceMetric) const
 Internal implementation of the virtual QPaintDevice::metric() function. More...
 
virtual void mouseDoubleClickEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse double click events for the widget. More...
 
virtual void mouseMoveEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget. More...
 
virtual void mousePressEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget. More...
 
virtual void mouseReleaseEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse release events for the widget. More...
 
virtual void moveEvent (QMoveEvent *)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter. More...
 
virtual void paintEvent (QPaintEvent *)
 This event handler can be reimplemented in a subclass to receive paint events passed in event. More...
 
virtual void paletteChange (const QPalette &)
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
virtual bool qwsEvent (QWSEvent *)
 This special event handler can be reimplemented in a subclass to receive native Qt for Embedded Linux events which are passed in the event parameter. More...
 
void resetInputContext ()
 This function can be called on the widget that currently has focus to reset the input method operating on it. More...
 
virtual void resizeEvent (QResizeEvent *)
 This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. More...
 
virtual void showEvent (QShowEvent *)
 This event handler can be reimplemented in a subclass to receive widget show events which are passed in the event parameter. More...
 
virtual void styleChange (QStyle &)
 
virtual void tabletEvent (QTabletEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive tablet events for the widget. More...
 
virtual void wheelEvent (QWheelEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive wheel events for the widget. More...
 
virtual void windowActivationChange (bool)
 
virtual bool winEvent (MSG *message, long *result)
 This special event handler can be reimplemented in a subclass to receive native Windows events which are passed in the message parameter. More...
 
virtual bool x11Event (XEvent *)
 This special event handler can be reimplemented in a subclass to receive native X11 events passed in the event parameter. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

bool animated
 whether manipulating dock widgets and tool bars is animated More...
 
bool dockNestingEnabled
 whether docks can be nested More...
 
DockOptions dockOptions
 the docking behavior of QMainWindow More...
 
bool documentMode
 whether the tab bar for tabbed dockwidgets is set to document mode. More...
 
QSize iconSize
 size of toolbar icons in this mainwindow. More...
 
QTabWidget::TabShape tabShape
 the tab shape used for tabbed dock widgets. More...
 
Qt::ToolButtonStyle toolButtonStyle
 style of toolbar buttons in this mainwindow. More...
 
bool unifiedTitleAndToolBarOnMac
 whether the window uses the unified title and toolbar look on Mac OS X More...
 

Additional Inherited Members

- Static Public Functions inherited from QWidget
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifer/handle id. More...
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input. More...
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input. More...
 
static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 Updates the widget's micro focus. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QPaintDevice
ushort painters
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QMainWindow class provides a main application window.

Qt Main Window Framework

A main window provides a framework for building an application's user interface. Qt has QMainWindow and its Main Window and Related Classes{related classes} for main window management. QMainWindow has its own layout to which you can add QToolBar, QDockWidget, a QMenuBar, and a QStatusBar. The layout has a center area that can be occupied by any kind of widget. You can see an image of the layout below.

mainwindowlayout.png
Note
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 Qt widget such as a QTextEdit or a QGraphicsView. Custom widgets can also be used for advanced applications. You set the central widget with setCentralWidget().

Main windows have either a single (SDI) or multiple (MDI) document interface. You create MDI applications in Qt by using a QMdiArea as the central widget.

We will now examine each of the other widgets that can be added to a main window. We give examples on how to create and add them.

Creating Menus

Qt implements menus in QMenu and QMainWindow keeps them in a QMenuBar. QActions are added to the menus, which display them as menu items.

You can add new menus to the main window's menu bar by calling menuBar(), which returns the QMenuBar for the window, and then add a menu with QMenuBar::addMenu().

QMainWindow comes with a default menu bar, but you can also set one yourself with setMenuBar(). If you wish to implement a custom menu bar (i.e., not use the QMenuBar widget), you can set it with setMenuWidget().

An example of how to create menus follows:

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

The createPopupMenu() function creates popup menus when the main window receives context menu events. The default implementation generates a menu with the checkable actions from the dock widgets and toolbars. You can reimplement createPopupMenu() for a custom menu.

Creating Toolbars

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

You control the initial position of toolbars by assigning them to a specific Qt::ToolBarArea. You can split an area by inserting a toolbar break - think of this as a line break in text editing - 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; you can set a fixed size with setIconSize(). You can alter the appearance of all tool buttons in the toolbars with setToolButtonStyle().

An example of toolbar creation follows:

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.

We give an example of how to create and add dock widgets to a main window:

QDockWidget *dockWidget = new QDockWidget(tr("Dock Widget"), this);
dockWidget->setWidget(dockWidgetContents);

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, {Application Example}, {Dock Widgets Example}, {MDI Example}, {SDI Example}, {Menus Example}

Definition at line 63 of file qmainwindow.h.

Enumerations

◆ DockOption

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

Since
4.3
  • AnimatedDocks Identical to the animated property.
  • AllowTabbedDocks 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.
  • ForceTabbedDocks Each dock area contains a single stack of tabbed dock widgets. In other words, dock widgets cannot be placed next to each other in a dock area. If this option is set, AllowNestedDocks has no effect.
  • VerticalTabs 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. See also setTabPosition() .

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.

Enumerator
AnimatedDocks 
AllowNestedDocks 
AllowTabbedDocks 
ForceTabbedDocks 
VerticalTabs 

Definition at line 87 of file qmainwindow.h.

87  {
88  AnimatedDocks = 0x01,
89  AllowNestedDocks = 0x02,
90  AllowTabbedDocks = 0x04,
91  ForceTabbedDocks = 0x08, // implies AllowTabbedDocks, !AllowNestedDocks
92  VerticalTabs = 0x10 // implies AllowTabbedDocks
93  };

Constructors and Destructors

◆ QMainWindow()

QMainWindow::QMainWindow ( QWidget parent = 0,
Qt::WindowFlags  flags = 0 
)
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.

Definition at line 374 of file qmainwindow.cpp.

375  : QWidget(*(new QMainWindowPrivate()), parent, flags | Qt::Window)
376 {
377  d_func()->init();
378 }
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189

◆ ~QMainWindow()

QMainWindow::~QMainWindow ( )

Destroys the main window.

Definition at line 400 of file qmainwindow.cpp.

401 { }

Functions

◆ addDockWidget() [1/2]

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

Adds the given dockwidget to the specified area.

Definition at line 1108 of file qmainwindow.cpp.

Referenced by QAxClientSite::qt_metacall(), and QScriptEngineDebugger::standardWindow().

1109 {
1110  if (!checkDockWidgetArea(area, "QMainWindow::addDockWidget"))
1111  return;
1112 
1113  Qt::Orientation orientation = Qt::Vertical;
1114  switch (area) {
1115  case Qt::TopDockWidgetArea:
1117  orientation = Qt::Horizontal;
1118  break;
1119  default:
1120  break;
1121  }
1122  d_func()->layout->removeWidget(dockwidget); // in case it was already in here
1123  addDockWidget(area, dockwidget, orientation);
1124 
1125 #ifdef Q_WS_MAC //drawer support
1127  extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp
1128  if (qt_mac_is_macdrawer(dockwidget)) {
1129  extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp
1130  window()->createWinId();
1131  dockwidget->window()->createWinId();
1133  if (dockwidget->isVisible()) {
1134  dockwidget->hide();
1135  dockwidget->show();
1136  }
1137  }
1138 #endif
1139 }
bool isVisible() const
Definition: qwidget.h:1005
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static bool checkDockWidgetArea(Qt::DockWidgetArea area, const char *where)
void show()
Shows the widget and its child widgets.
void hide()
Hides the widget.
Definition: qwidget.h:501
DockWidgetArea
Definition: qnamespace.h:1337
void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget)
Adds the given dockwidget to the specified area.
bool qt_mac_set_drawer_preferred_edge(QWidget *w, Qt::DockWidgetArea where)
Definition: qwidget_mac.mm:321
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
void createWinId()
Definition: qwidget.cpp:2626
Orientation
Definition: qnamespace.h:174
bool qt_mac_is_macdrawer(const QWidget *w)
Definition: qwidget_mac.mm:306
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ addDockWidget() [2/2]

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

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

Definition at line 1158 of file qmainwindow.cpp.

1160 {
1161  if (!checkDockWidgetArea(area, "QMainWindow::addDockWidget"))
1162  return;
1163 
1164  // add a window to an area, placing done relative to the previous
1165  d_func()->layout->addDockWidget(area, dockwidget, orientation);
1166 }
static bool checkDockWidgetArea(Qt::DockWidgetArea area, const char *where)
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ addToolBar() [1/3]

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

Definition at line 764 of file qmainwindow.cpp.

Referenced by addToolBar(), QScriptEngineDebugger::standardWindow(), and QMenuBarPrivate::updateCornerWidgetToolBar().

765 {
766  if (!checkToolBarArea(area, "QMainWindow::addToolBar"))
767  return;
768 
769  Q_D(QMainWindow);
770 
772  toolbar, SLOT(_q_updateIconSize(QSize)));
774  toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));
775 
776  if(toolbar->d_func()->state && toolbar->d_func()->state->dragging) {
777  //removing a toolbar which is dragging will cause crash
778 #ifndef QT_NO_DOCKWIDGET
779  bool animated = isAnimated();
780  setAnimated(false);
781 #endif
782  toolbar->d_func()->endDrag();
783 #ifndef QT_NO_DOCKWIDGET
784  setAnimated(animated);
785 #endif
786  }
787 
788  if (!d->layout->usesHIToolBar(toolbar)) {
789  d->layout->removeWidget(toolbar);
790  } else {
791  d->layout->removeToolBar(toolbar);
792  }
793 
794  toolbar->d_func()->_q_updateIconSize(d->iconSize);
795  toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle);
797  toolbar, SLOT(_q_updateIconSize(QSize)));
799  toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));
800 
801  d->layout->addToolBar(area, toolbar);
802 }
double d
Definition: qnumeric_p.h:62
#define SLOT(a)
Definition: qobjectdefs.h:226
void setAnimated(bool enabled)
#define Q_D(Class)
Definition: qglobal.h:2482
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
This signal is emitted when the style used for tool buttons in the window is changed.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
static bool checkToolBarArea(Qt::ToolBarArea area, const char *where)
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
bool isAnimated() const
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
ToolButtonStyle
Definition: qnamespace.h:1572
bool animated
whether manipulating dock widgets and tool bars is animated
Definition: qmainwindow.h:72
void iconSizeChanged(const QSize &iconSize)
This signal is emitted when the size of the icons used in the window is changed.
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ addToolBar() [2/3]

void QMainWindow::addToolBar ( QToolBar toolbar)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Equivalent of calling addToolBar(Qt::TopToolBarArea, toolbar)

Definition at line 807 of file qmainwindow.cpp.

808 { addToolBar(Qt::TopToolBarArea, toolbar); }
void addToolBar(Qt::ToolBarArea area, QToolBar *toolbar)
Adds the toolbar into the specified area in this main window.

◆ addToolBar() [3/3]

QToolBar * QMainWindow::addToolBar ( const QString title)

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
setWindowTitle()

Definition at line 821 of file qmainwindow.cpp.

822 {
823  QToolBar *toolBar = new QToolBar(this);
824  toolBar->setWindowTitle(title);
825  addToolBar(toolBar);
826  return toolBar;
827 }
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
void addToolBar(Qt::ToolBarArea area, QToolBar *toolbar)
Adds the toolbar into the specified area in this main window.

◆ addToolBarBreak()

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

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

Definition at line 733 of file qmainwindow.cpp.

734 {
735  if (!checkToolBarArea(area, "QMainWindow::addToolBarBreak"))
736  return;
737  d_func()->layout->addToolBarBreak(area);
738 }
static bool checkToolBarArea(Qt::ToolBarArea area, const char *where)
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ centralWidget()

QWidget * QMainWindow::centralWidget ( ) const

Returns the central widget for the main window.

This function returns zero if the central widget has not been set.

See also
setCentralWidget()

Definition at line 651 of file qmainwindow.cpp.

652 { return d_func()->layout->centralWidget(); }

◆ contextMenuEvent()

void QMainWindow::contextMenuEvent ( QContextMenuEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1631 of file qmainwindow.cpp.

1632 {
1633  event->ignore();
1634  // only show the context menu for direct QDockWidget and QToolBar
1635  // children and for the menu bar as well
1636  QWidget *child = childAt(event->pos());
1637  while (child && child != this) {
1638 #ifndef QT_NO_MENUBAR
1639  if (QMenuBar *mb = qobject_cast<QMenuBar *>(child)) {
1640  if (mb->parentWidget() != this)
1641  return;
1642  break;
1643  }
1644 #endif
1645 #ifndef QT_NO_DOCKWIDGET
1646  if (QDockWidget *dw = qobject_cast<QDockWidget *>(child)) {
1647  if (dw->parentWidget() != this)
1648  return;
1649  if (dw->widget()
1650  && dw->widget()->geometry().contains(child->mapFrom(this, event->pos()))) {
1651  // ignore the event if the mouse is over the QDockWidget contents
1652  return;
1653  }
1654  break;
1655  }
1656 #endif // QT_NO_DOCKWIDGET
1657 #ifndef QT_NO_TOOLBAR
1658  if (QToolBar *tb = qobject_cast<QToolBar *>(child)) {
1659  if (tb->parentWidget() != this)
1660  return;
1661  break;
1662  }
1663 #endif
1664  child = child->parentWidget();
1665  }
1666  if (child == this)
1667  return;
1668 
1669 #ifndef QT_NO_MENU
1670  QMenu *popup = createPopupMenu();
1671  if (popup) {
1672  if (!popup->isEmpty()) {
1674  popup->popup(event->globalPos());
1675  event->accept();
1676  } else {
1677  delete popup;
1678  }
1679  }
1680 #endif
1681 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
virtual QMenu * createPopupMenu()
Returns a popup menu containing checkable entries for the toolbars and dock widgets present in the ma...
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
void popup(const QPoint &pos, QAction *at=0)
Displays the menu so that the action atAction will be at the specified global position p...
Definition: qmenu.cpp:1847
const QPoint & pos() const
Returns the position of the mouse pointer relative to the widget that received the event...
Definition: qevent.h:412
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool isEmpty() const
Returns true if there are no visible actions inserted into the menu, false otherwise.
Definition: qmenu.cpp:1737
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
QWidget * childAt(int x, int y) const
Returns the visible child widget at the position ({x}, {y}) in the widget&#39;s coordinate system...
Definition: qwidget.h:934
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition: qevent.h:413
QPoint mapFrom(QWidget *, const QPoint &) const
Translates the widget coordinate pos from the coordinate system of parent to this widget&#39;s coordinate...
Definition: qwidget.cpp:4433

◆ corner()

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

Returns the dock widget area that occupies the specified corner.

See also
setCorner()

Definition at line 708 of file qmainwindow.cpp.

709 { return d_func()->layout->corner(corner); }
Qt::DockWidgetArea corner(Qt::Corner corner) const
Returns the dock widget area that occupies the specified corner.

◆ createPopupMenu()

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 function 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()

Definition at line 1700 of file qmainwindow.cpp.

Referenced by contextMenuEvent().

1701 {
1702  Q_D(QMainWindow);
1703  QMenu *menu = 0;
1704 #ifndef QT_NO_DOCKWIDGET
1705  QList<QDockWidget *> dockwidgets = findChildren<QDockWidget *>();
1706  if (dockwidgets.size()) {
1707  menu = new QMenu(this);
1708  for (int i = 0; i < dockwidgets.size(); ++i) {
1709  QDockWidget *dockWidget = dockwidgets.at(i);
1710  if (dockWidget->parentWidget() == this
1711  && !d->layout->layoutState.dockAreaLayout.indexOf(dockWidget).isEmpty()) {
1712  menu->addAction(dockwidgets.at(i)->toggleViewAction());
1713  }
1714  }
1715  menu->addSeparator();
1716  }
1717 #endif // QT_NO_DOCKWIDGET
1718 #ifndef QT_NO_TOOLBAR
1719  QList<QToolBar *> toolbars = findChildren<QToolBar *>();
1720  if (toolbars.size()) {
1721  if (!menu)
1722  menu = new QMenu(this);
1723  for (int i = 0; i < toolbars.size(); ++i) {
1724  QToolBar *toolBar = toolbars.at(i);
1725  if (toolBar->parentWidget() == this
1726  && (!d->layout->layoutState.toolBarAreaLayout.indexOf(toolBar).isEmpty()
1728  && toolBarArea(toolBar) == Qt::TopToolBarArea))) {
1729  menu->addAction(toolbars.at(i)->toggleViewAction());
1730  }
1731  }
1732  }
1733 #endif
1734  Q_UNUSED(d);
1735  return menu;
1736 }
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
bool unifiedTitleAndToolBarOnMac() const
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
QAction * toggleViewAction() const
Returns a checkable action that can be used to show or close this dock widget.
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::ToolBarArea toolBarArea(QToolBar *toolbar) const
Returns the Qt::ToolBarArea for toolbar.
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
QAction * toggleViewAction() const
Returns a checkable action that can be used to show or hide this toolbar.
Definition: qtoolbar.cpp:1327
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition: qmenu.cpp:1583
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ dockOptions()

DockOptions QMainWindow::dockOptions ( ) const

Referenced by setDockOptions().

◆ dockWidgetArea()

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

Definition at line 1261 of file qmainwindow.cpp.

1262 { return d_func()->layout->dockWidgetArea(dockwidget); }

◆ documentMode()

bool QMainWindow::documentMode ( ) const

Referenced by checkDockWidgetArea().

◆ event()

bool QMainWindow::event ( QEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1403 of file qmainwindow.cpp.

1404 {
1405  Q_D(QMainWindow);
1406  switch (event->type()) {
1407 
1408 #ifndef QT_NO_DOCKWIDGET
1409  case QEvent::Paint: {
1410  QPainter p(this);
1411  QRegion r = static_cast<QPaintEvent*>(event)->region();
1412  d->layout->layoutState.dockAreaLayout.paintSeparators(&p, this, r, d->hoverPos);
1413  break;
1414  }
1415 
1416 #ifndef QT_NO_CURSOR
1417  case QEvent::HoverMove: {
1418  d->adjustCursor(static_cast<QHoverEvent*>(event)->pos());
1419  break;
1420  }
1421 
1422  // We don't want QWidget to call update() on the entire QMainWindow
1423  // on HoverEnter and HoverLeave, hence accept the event (return true).
1424  case QEvent::HoverEnter:
1425  return true;
1426  case QEvent::HoverLeave:
1427  d->adjustCursor(QPoint(0, 0));
1428  return true;
1429  case QEvent::ShortcutOverride: // when a menu pops up
1430  d->adjustCursor(QPoint(0, 0));
1431  break;
1432 #endif // QT_NO_CURSOR
1433 
1434  case QEvent::MouseButtonPress: {
1435  QMouseEvent *e = static_cast<QMouseEvent*>(event);
1436  if (e->button() == Qt::LeftButton && d->layout->startSeparatorMove(e->pos())) {
1437  // The click was on a separator, eat this event
1438  e->accept();
1439  return true;
1440  }
1441  break;
1442  }
1443 
1444  case QEvent::MouseMove: {
1445  QMouseEvent *e = static_cast<QMouseEvent*>(event);
1446 
1447 #ifndef QT_NO_CURSOR
1448  d->adjustCursor(e->pos());
1449 #endif
1450  if (e->buttons() & Qt::LeftButton) {
1451  if (d->layout->separatorMove(e->pos())) {
1452  // We're moving a separator, eat this event
1453  e->accept();
1454  return true;
1455  }
1456  }
1457 
1458  break;
1459  }
1460 
1462  QMouseEvent *e = static_cast<QMouseEvent*>(event);
1463  if (d->layout->endSeparatorMove(e->pos())) {
1464  // We've released a separator, eat this event
1465  e->accept();
1466  return true;
1467  }
1468  break;
1469  }
1470 
1471 #endif
1472 
1473 #ifndef QT_NO_TOOLBAR
1474  case QEvent::ToolBarChange: {
1475  d->layout->toggleToolBarsVisible();
1476  return true;
1477  }
1478 #endif
1479 
1480 #ifndef QT_NO_STATUSTIP
1481  case QEvent::StatusTip:
1482 #ifndef QT_NO_STATUSBAR
1483  if (QStatusBar *sb = d->layout->statusBar())
1484  sb->showMessage(static_cast<QStatusTipEvent*>(event)->tip());
1485  else
1486 #endif
1487  static_cast<QStatusTipEvent*>(event)->ignore();
1488  return true;
1489 #endif // QT_NO_STATUSTIP
1490 
1491  case QEvent::StyleChange:
1492 #ifndef QT_NO_DOCKWIDGET
1493  d->layout->layoutState.dockAreaLayout.styleChangedEvent();
1494 #endif
1495  if (!d->explicitIconSize)
1496  setIconSize(QSize());
1497  break;
1498 #ifdef Q_WS_MAC
1499  case QEvent::Show:
1500  d->layout->blockVisiblityCheck = false;
1502  d->layout->syncUnifiedToolbarVisibility();
1503  break;
1505  {
1506  if (isHidden()) {
1507  // We are coming out of a minimize, leave things as is.
1508  d->layout->blockVisiblityCheck = true;
1509  }
1510 # ifdef QT_MAC_USE_COCOA
1511  // We need to update the HIToolbar status when we go out of or into fullscreen.
1512  QWindowStateChangeEvent *wce = static_cast<QWindowStateChangeEvent *>(event);
1514  d->layout->updateHIToolBarStatus();
1515  }
1516 # endif // Cocoa
1517  }
1518  break;
1519 #endif // Q_WS_MAC
1520 #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR)
1521  case QEvent::CursorChange:
1522  if (d->cursorAdjusted) {
1523  d->oldCursor = cursor();
1524  d->hasOldCursor = testAttribute(Qt::WA_SetCursor);
1525  }
1526  break;
1527 #endif
1528  default:
1529  break;
1530  }
1531 
1532  return QWidget::event(event);
1533 }
QPoint pos() const
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
Qt::WindowStates oldState() const
Returns the state of the window before the change.
Definition: qevent.h:712
QCursor cursor() const
bool unifiedTitleAndToolBarOnMac() const
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
static bool ignore(const char *test, const char *const *table)
Definition: qaxserver.cpp:660
void setIconSize(const QSize &iconSize)
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
The QStatusBar class provides a horizontal bar suitable for presenting status information.
Definition: qstatusbar.h:57
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
bool event(QEvent *event)
Reimplemented Function
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
The QWindowStateChangeEvent class provides the window state before a window state change...
Definition: qevent.h:705
The QStatusTipEvent class provides an event that is used to show messages in a status bar...
Definition: qevent.h:606
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ iconSize()

QSize QMainWindow::iconSize ( ) const

Referenced by setDockOptions(), and setIconSize().

◆ iconSizeChanged

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

Referenced by addToolBar(), insertToolBar(), and setIconSize().

◆ insertToolBar()

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

Definition at line 837 of file qmainwindow.cpp.

838 {
839  Q_D(QMainWindow);
840 
841  d->layout->removeToolBar(toolbar);
842 
843  toolbar->d_func()->_q_updateIconSize(d->iconSize);
844  toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle);
846  toolbar, SLOT(_q_updateIconSize(QSize)));
848  toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));
849 
850  d->layout->insertToolBar(before, toolbar);
851 }
double d
Definition: qnumeric_p.h:62
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_D(Class)
Definition: qglobal.h:2482
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
This signal is emitted when the style used for tool buttons in the window is changed.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
ToolButtonStyle
Definition: qnamespace.h:1572
void iconSizeChanged(const QSize &iconSize)
This signal is emitted when the size of the icons used in the window is changed.

◆ insertToolBarBreak()

void QMainWindow::insertToolBarBreak ( QToolBar before)

Inserts a toolbar break before the toolbar specified by before.

Definition at line 743 of file qmainwindow.cpp.

744 { d_func()->layout->insertToolBarBreak(before); }

◆ isAnimated()

bool QMainWindow::isAnimated ( ) const

Definition at line 914 of file qmainwindow.cpp.

Referenced by addToolBar().

915 {
916  Q_D(const QMainWindow);
917  return d->layout->dockOptions & AnimatedDocks;
918 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ isDockNestingEnabled()

bool QMainWindow::isDockNestingEnabled ( ) const

Definition at line 956 of file qmainwindow.cpp.

957 {
958  Q_D(const QMainWindow);
959  return d->layout->dockOptions & AllowNestedDocks;
960 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ isSeparator()

bool QMainWindow::isSeparator ( const QPoint pos) const
Warning
This function is not part of the public interface.

Definition at line 1616 of file qmainwindow.cpp.

1617 {
1618 #ifndef QT_NO_DOCKWIDGET
1619  Q_D(const QMainWindow);
1620  return !d->layout->layoutState.dockAreaLayout.findSeparator(pos).isEmpty();
1621 #else
1622  Q_UNUSED(pos);
1623  return false;
1624 #endif
1625 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ menuBar()

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, don't 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()

Definition at line 527 of file qmainwindow.cpp.

Referenced by menuWidget(), setMenuBar(), setMenuWidget(), and QScriptEngineDebugger::standardWindow().

528 {
530  if (!menuBar) {
531  QMainWindow *self = const_cast<QMainWindow *>(this);
532  menuBar = new QMenuBar(self);
533  self->setMenuBar(menuBar);
534  }
535  return menuBar;
536 }
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QWidget * menuBar() const
Returns the menu bar set for this layout, or 0 if no menu bar is set.
Definition: qlayout.cpp:1149
QMenuBar * menuBar() const
Returns the menu bar for the main window.
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073

◆ menuWidget()

QWidget * QMainWindow::menuWidget ( ) const

Returns the menu bar for the main window.

Since
4.2

This function returns null if a menu bar hasn't been constructed yet.

Definition at line 578 of file qmainwindow.cpp.

Referenced by QMdiSubWindowPrivate::drawTitleBarWhenMaximized().

579 {
580  QWidget *menuBar = d_func()->layout->menuBar();
581  return menuBar;
582 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QWidget * menuBar() const
Returns the menu bar set for this layout, or 0 if no menu bar is set.
Definition: qlayout.cpp:1149
QMenuBar * menuBar() const
Returns the menu bar for the main window.
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073

◆ removeDockWidget()

void QMainWindow::removeDockWidget ( QDockWidget dockwidget)

Removes the dockwidget from the main window layout and hides it.

Note that the dockwidget is not deleted.

Definition at line 1246 of file qmainwindow.cpp.

1247 {
1248  if (dockwidget) {
1249  d_func()->layout->removeWidget(dockwidget);
1250  dockwidget->hide();
1251  }
1252 }
void hide()
Hides the widget.
Definition: qwidget.h:501

◆ removeToolBar()

void QMainWindow::removeToolBar ( QToolBar toolbar)

Removes the toolbar from the main window layout and hides it.

Note that the toolbar is not deleted.

Definition at line 857 of file qmainwindow.cpp.

858 {
859  if (toolbar) {
860  d_func()->layout->removeToolBar(toolbar);
861  toolbar->hide();
862  }
863 }
void hide()
Hides the widget.
Definition: qwidget.h:501

◆ removeToolBarBreak()

void QMainWindow::removeToolBarBreak ( QToolBar before)

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

Definition at line 750 of file qmainwindow.cpp.

751 {
752  Q_D(QMainWindow);
753  d->layout->removeToolBarBreak(before);
754 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ restoreDockWidget()

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

Definition at line 1149 of file qmainwindow.cpp.

1150 {
1151  return d_func()->layout->restoreDockWidget(dockwidget);
1152 }

◆ restoreState()

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 function returns false; otherwise, the state is restored, and this function 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()

Definition at line 1310 of file qmainwindow.cpp.

Referenced by QScriptEngineDebugger::standardWindow().

1311 {
1312  if (state.isEmpty())
1313  return false;
1314  QByteArray sd = state;
1316  int marker, v;
1317  stream >> marker;
1318  stream >> v;
1319  if (stream.status() != QDataStream::Ok || marker != QMainWindowLayout::VersionMarker || v != version)
1320  return false;
1321  bool restored = d_func()->layout->restoreState(stream);
1322  return restored;
1323 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static FILE * stream
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71

◆ saveState()

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 like this:

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

Definition at line 1285 of file qmainwindow.cpp.

1286 {
1287  QByteArray data;
1290  stream << version;
1291  d_func()->layout->saveState(stream);
1292  return data;
1293 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static FILE * stream
QWidgetData * data
Definition: qwidget.h:815
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71

◆ setAnimated

void QMainWindow::setAnimated ( bool  enabled)
slot

Definition at line 920 of file qmainwindow.cpp.

Referenced by addToolBar().

921 {
922  Q_D(QMainWindow);
923 
924  DockOptions opts = d->layout->dockOptions;
925  if (enabled)
926  opts |= AnimatedDocks;
927  else
928  opts &= ~AnimatedDocks;
929 
930  d->layout->setDockOptions(opts);
931 }
double d
Definition: qnumeric_p.h:62
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
#define Q_D(Class)
Definition: qglobal.h:2482
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ setCentralWidget()

void QMainWindow::setCentralWidget ( QWidget widget)

Sets the given widget to be the main window's central widget.

Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.

See also
centralWidget()

Definition at line 662 of file qmainwindow.cpp.

Referenced by QScriptEngineDebugger::standardWindow().

663 {
664  Q_D(QMainWindow);
665  if (d->layout->centralWidget() && d->layout->centralWidget() != widget) {
666  d->layout->centralWidget()->hide();
667  d->layout->centralWidget()->deleteLater();
668  }
669  d->layout->setCentralWidget(widget);
670 }
double d
Definition: qnumeric_p.h:62
QPointer< QWidget > widget
#define Q_D(Class)
Definition: qglobal.h:2482
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ setCorner()

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

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

See also
corner()

Definition at line 679 of file qmainwindow.cpp.

680 {
681  bool valid = false;
682  switch (corner) {
683  case Qt::TopLeftCorner:
685  break;
686  case Qt::TopRightCorner:
688  break;
691  break;
694  break;
695  }
696  if (!valid)
697  qWarning("QMainWindow::setCorner(): 'area' is not valid for 'corner'");
698  else
699  d_func()->layout->setCorner(corner, area);
700 }
Qt::DockWidgetArea corner(Qt::Corner corner) const
Returns the dock widget area that occupies the specified corner.
Q_CORE_EXPORT void qWarning(const char *,...)
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ setDockNestingEnabled

void QMainWindow::setDockNestingEnabled ( bool  enabled)
slot

Definition at line 962 of file qmainwindow.cpp.

963 {
964  Q_D(QMainWindow);
965 
966  DockOptions opts = d->layout->dockOptions;
967  if (enabled)
968  opts |= AllowNestedDocks;
969  else
970  opts &= ~AllowNestedDocks;
971 
972  d->layout->setDockOptions(opts);
973 }
double d
Definition: qnumeric_p.h:62
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
#define Q_D(Class)
Definition: qglobal.h:2482
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ setDockOptions()

void QMainWindow::setDockOptions ( DockOptions  options)

Definition at line 460 of file qmainwindow.cpp.

461 {
462  Q_D(QMainWindow);
463  d->layout->setDockOptions(opt);
464 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ setDocumentMode()

void QMainWindow::setDocumentMode ( bool  enabled)

Definition at line 1036 of file qmainwindow.cpp.

1037 {
1038  d_func()->layout->setDocumentMode(enabled);
1039 }
bool enabled
whether the widget is enabled
Definition: qwidget.h:157

◆ setIconSize()

void QMainWindow::setIconSize ( const QSize iconSize)

Definition at line 475 of file qmainwindow.cpp.

Referenced by event().

476 {
477  Q_D(QMainWindow);
478  QSize sz = iconSize;
479  if (!sz.isValid()) {
480  const int metric = style()->pixelMetric(QStyle::PM_ToolBarIconSize, 0, this);
481  sz = QSize(metric, metric);
482  }
483  if (d->iconSize != sz) {
484  d->iconSize = sz;
485  emit iconSizeChanged(d->iconSize);
486  }
487  d->explicitIconSize = iconSize.isValid();
488 }
double d
Definition: qnumeric_p.h:62
int metric(PaintDeviceMetric) const
Internal implementation of the virtual QPaintDevice::metric() function.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
#define emit
Definition: qobjectdefs.h:76
QSize iconSize() const
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void iconSizeChanged(const QSize &iconSize)
This signal is emitted when the size of the icons used in the window is changed.

◆ setMenuBar()

void QMainWindow::setMenuBar ( QMenuBar menuBar)

Sets the menu bar for the main window to menuBar.

Note: QMainWindow takes ownership of the menuBar pointer and deletes it at the appropriate time.

See also
menuBar()

Definition at line 546 of file qmainwindow.cpp.

547 {
548  QLayout *topLayout = layout();
549 
550  if (topLayout->menuBar() && topLayout->menuBar() != menuBar) {
551  // Reparent corner widgets before we delete the old menu bar.
552  QMenuBar *oldMenuBar = qobject_cast<QMenuBar *>(topLayout->menuBar());
553  if (menuBar) {
554  // TopLeftCorner widget.
555  QWidget *cornerWidget = oldMenuBar->cornerWidget(Qt::TopLeftCorner);
556  if (cornerWidget)
557  menuBar->setCornerWidget(cornerWidget, Qt::TopLeftCorner);
558  // TopRightCorner widget.
559  cornerWidget = oldMenuBar->cornerWidget(Qt::TopRightCorner);
560  if (cornerWidget)
561  menuBar->setCornerWidget(cornerWidget, Qt::TopRightCorner);
562  }
563  oldMenuBar->hide();
564  oldMenuBar->deleteLater();
565  }
566  topLayout->setMenuBar(menuBar);
567 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QWidget * menuBar() const
Returns the menu bar set for this layout, or 0 if no menu bar is set.
Definition: qlayout.cpp:1149
QWidget * cornerWidget(Qt::Corner corner=Qt::TopRightCorner) const
Returns the widget on the left of the first or on the right of the last menu item, depending on corner.
Definition: qmenubar.cpp:2022
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
void setMenuBar(QWidget *w)
Tells the geometry manager to place the menu bar widget at the top of parentWidget(), outside QWidget::contentsMargins().
Definition: qlayout.cpp:1131
void hide()
Hides the widget.
Definition: qwidget.h:501
QMenuBar * menuBar() const
Returns the menu bar for the main window.
void setCornerWidget(QWidget *w, Qt::Corner corner=Qt::TopRightCorner)
This sets the given widget to be shown directly on the left of the first menu item, or on the right of the last menu item, depending on corner.
Definition: qmenubar.cpp:1980
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145

◆ setMenuWidget()

void QMainWindow::setMenuWidget ( QWidget menuBar)

Sets the menu bar for the main window to menuBar.

Since
4.2

QMainWindow takes ownership of the menuBar pointer and deletes it at the appropriate time.

Definition at line 595 of file qmainwindow.cpp.

596 {
597  Q_D(QMainWindow);
598  if (d->layout->menuBar() && d->layout->menuBar() != menuBar) {
599  d->layout->menuBar()->hide();
600  d->layout->menuBar()->deleteLater();
601  }
602  d->layout->setMenuBar(menuBar);
603 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QMenuBar * menuBar() const
Returns the menu bar for the main window.
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ setStatusBar()

void QMainWindow::setStatusBar ( QStatusBar statusbar)

Sets the status bar for the main window to statusbar.

Setting the status bar to 0 will remove it from the main window. Note that QMainWindow takes ownership of the statusbar pointer and deletes it at the appropriate time.

See also
statusBar()

Definition at line 634 of file qmainwindow.cpp.

635 {
636  Q_D(QMainWindow);
637  if (d->layout->statusBar() && d->layout->statusBar() != statusbar) {
638  d->layout->statusBar()->hide();
639  d->layout->statusBar()->deleteLater();
640  }
641  d->layout->setStatusBar(statusbar);
642 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ setTabPosition()

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

Sets the tab position for the given dock widget areas to the specified tabPosition.

Since
4.5

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

Definition at line 1099 of file qmainwindow.cpp.

1100 {
1101  d_func()->layout->setTabPosition(areas, tabPosition);
1102 }
QTabWidget::TabPosition tabPosition(Qt::DockWidgetArea area) const
Returns the tab position for area.

◆ setTabShape()

void QMainWindow::setTabShape ( QTabWidget::TabShape  tabShape)

Definition at line 1060 of file qmainwindow.cpp.

1061 {
1062  d_func()->layout->setTabShape(tabShape);
1063 }
QTabWidget::TabShape tabShape() const

◆ setToolButtonStyle()

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

Definition at line 502 of file qmainwindow.cpp.

503 {
504  Q_D(QMainWindow);
505  if (d->toolButtonStyle == toolButtonStyle)
506  return;
507  d->toolButtonStyle = toolButtonStyle;
508  emit toolButtonStyleChanged(d->toolButtonStyle);
509 }
double d
Definition: qnumeric_p.h:62
Qt::ToolButtonStyle toolButtonStyle() const
#define Q_D(Class)
Definition: qglobal.h:2482
void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
This signal is emitted when the style used for tool buttons in the window is changed.
#define emit
Definition: qobjectdefs.h:76
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ setUnifiedTitleAndToolBarOnMac()

void QMainWindow::setUnifiedTitleAndToolBarOnMac ( bool  set)

Definition at line 1567 of file qmainwindow.cpp.

Referenced by QWidget::showFullScreen(), QWidget::showMaximized(), QWidget::showNormal(), and QScriptEngineDebugger::standardWindow().

1568 {
1569 #ifdef Q_WS_MAC
1570  Q_D(QMainWindow);
1571  if (!isWindow() || d->useHIToolBar == set || QSysInfo::MacintoshVersion < QSysInfo::MV_10_3)
1572  return;
1573 
1574  d->useHIToolBar = set;
1575  createWinId(); // We need the hiview for down below.
1576 
1577 #ifdef QT_MAC_USE_COCOA
1578  // Activate the unified toolbar with the raster engine.
1579  if (windowSurface() && set) {
1580  d->layout->unifiedSurface = new QUnifiedToolbarSurface(this);
1581  }
1582 #endif // QT_MAC_USE_COCOA
1583 
1584  d->layout->updateHIToolBarStatus();
1585 
1586 #ifdef QT_MAC_USE_COCOA
1587  // Deactivate the unified toolbar with the raster engine.
1588  if (windowSurface() && !set) {
1589  if (d->layout->unifiedSurface) {
1590  delete d->layout->unifiedSurface;
1591  d->layout->unifiedSurface = 0;
1592  }
1593  }
1594 #endif // QT_MAC_USE_COCOA
1595 
1596  // Enabling the unified toolbar clears the opaque size grip setting, update it.
1597  d->macUpdateOpaqueSizeGrip();
1598 #else
1599  Q_UNUSED(set)
1600 #endif
1601 }
double d
Definition: qnumeric_p.h:62
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
#define Q_D(Class)
Definition: qglobal.h:2482
QWindowSurface * windowSurface() const
Returns the QWindowSurface this widget will be drawn into.
Definition: qwidget.cpp:12819
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
void createWinId()
Definition: qwidget.cpp:2626
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
friend class QUnifiedToolbarSurface
Definition: qwidget.h:782

◆ splitDockWidget()

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.

Note: 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.

Note: 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()

Definition at line 1189 of file qmainwindow.cpp.

1191 {
1192  d_func()->layout->splitDockWidget(after, dockwidget, orientation);
1193 }

◆ statusBar()

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

Definition at line 613 of file qmainwindow.cpp.

614 {
615  QStatusBar *statusbar = d_func()->layout->statusBar();
616  if (!statusbar) {
617  QMainWindow *self = const_cast<QMainWindow *>(this);
618  statusbar = new QStatusBar(self);
620  self->setStatusBar(statusbar);
621  }
622  return statusbar;
623 }
The QStatusBar class provides a horizontal bar suitable for presenting status information.
Definition: qstatusbar.h:57
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
void setSizePolicy(QSizePolicy)
Definition: qwidget.cpp:10198

◆ tabifiedDockWidgets()

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

Returns the dock widgets that are tabified together with dockwidget.

Since
4.5
See also
tabifyDockWidget()

Definition at line 1218 of file qmainwindow.cpp.

1219 {
1220  QList<QDockWidget*> ret;
1221 #if defined(QT_NO_TABBAR)
1222  Q_UNUSED(dockwidget);
1223 #else
1224  const QDockAreaLayoutInfo *info = d_func()->layout->layoutState.dockAreaLayout.info(dockwidget);
1225  if (info && info->tabbed && info->tabBar) {
1226  for(int i = 0; i < info->item_list.count(); ++i) {
1227  const QDockAreaLayoutItem &item = info->item_list.at(i);
1228  if (item.widgetItem) {
1229  if (QDockWidget *dock = qobject_cast<QDockWidget*>(item.widgetItem->widget())) {
1230  if (dock != dockwidget) {
1231  ret += dock;
1232  }
1233  }
1234  }
1235  }
1236  }
1237 #endif
1238  return ret;
1239 }
QList< QDockAreaLayoutItem > item_list
static mach_timebase_info_data_t info
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QLayoutItem * widgetItem

◆ 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()

Definition at line 1203 of file qmainwindow.cpp.

Referenced by QScriptEngineDebugger::standardWindow().

1204 {
1205  d_func()->layout->tabifyDockWidget(first, second);
1206 }

◆ tabPosition()

QTabWidget::TabPosition QMainWindow::tabPosition ( Qt::DockWidgetArea  area) const

Returns the tab position for area.

Since
4.5
Note
The VerticalTabs dock option overrides the tab positions returned by this function.
See also
setTabPosition(), tabShape()

Definition at line 1078 of file qmainwindow.cpp.

1079 {
1080  if (!checkDockWidgetArea(area, "QMainWindow::tabPosition"))
1081  return QTabWidget::South;
1082  return d_func()->layout->tabPosition(area);
1083 }
static bool checkDockWidgetArea(Qt::DockWidgetArea area, const char *where)
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ tabShape()

QTabWidget::TabShape QMainWindow::tabShape ( ) const

Referenced by setDocumentMode().

◆ toolBarArea()

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

Definition at line 872 of file qmainwindow.cpp.

Referenced by createPopupMenu(), and toolbarInUnifiedToolBar().

873 { return d_func()->layout->toolBarArea(toolbar); }

◆ toolBarBreak()

bool QMainWindow::toolBarBreak ( QToolBar toolbar) const

Returns whether there is a toolbar break before the toolbar.

See also
addToolBarBreak(), insertToolBarBreak()

Definition at line 882 of file qmainwindow.cpp.

883 {
884  return d_func()->layout->toolBarBreak(toolbar);
885 }

◆ toolButtonStyle()

Qt::ToolButtonStyle QMainWindow::toolButtonStyle ( ) const

Referenced by setIconSize(), and setToolButtonStyle().

◆ toolButtonStyleChanged

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

Referenced by addToolBar(), insertToolBar(), and setToolButtonStyle().

◆ unifiedTitleAndToolBarOnMac()

bool QMainWindow::unifiedTitleAndToolBarOnMac ( ) const

Properties

◆ animated

QMainWindow::animated
private

whether manipulating dock widgets and tool bars is animated

Since
4.2

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().

Definition at line 72 of file qmainwindow.h.

Referenced by addToolBar().

◆ dockNestingEnabled

QMainWindow::dockNestingEnabled
private

whether docks can be nested

Since
4.2

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().

Definition at line 79 of file qmainwindow.h.

◆ dockOptions

QMainWindow::DockOptions QMainWindow::dockOptions
private

the docking behavior of QMainWindow

Since
4.3

The default value is AnimatedDocks | AllowTabbedDocks.

Definition at line 81 of file qmainwindow.h.

Referenced by QDockAreaLayout::gapIndex().

◆ documentMode

bool QMainWindow::documentMode
private

whether the tab bar for tabbed dockwidgets is set to document mode.

Since
4.5

The default is false.

See also
QTabBar::documentMode

Definition at line 74 of file qmainwindow.h.

◆ iconSize

QSize QMainWindow::iconSize
private

size of toolbar icons in this mainwindow.

The default is the default tool bar icon size of the GUI style. Note that the icons used must be at least of this size as the icons are only scaled down.

Definition at line 69 of file qmainwindow.h.

Referenced by QToolBar::setIconSize().

◆ tabShape

QTabWidget::TabShape QMainWindow::tabShape
private

the tab shape used for tabbed dock widgets.

Since
4.5

The default is QTabWidget::Rounded .

See also
setTabPosition()

Definition at line 77 of file qmainwindow.h.

◆ toolButtonStyle

Qt::ToolButtonStyle QMainWindow::toolButtonStyle
private

style of toolbar buttons in this mainwindow.

The default is Qt::ToolButtonIconOnly.

Definition at line 70 of file qmainwindow.h.

◆ unifiedTitleAndToolBarOnMac

bool QMainWindow::unifiedTitleAndToolBarOnMac
private

whether the window uses the unified title and toolbar look on Mac OS X

Since
4.3

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 Qt 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 cannot 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)
  • Before Qt 4.5, if you called showFullScreen() on the main window, the QToolbar would disappear since it is considered to be part of the title bar. Qt 4.5 and up will now work around this by pulling the toolbars out and back into the regular toolbar and vice versa when you swap out.

Setting this back to false will remove these restrictions.

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

Definition at line 83 of file qmainwindow.h.

Referenced by QToolBar::allowedAreas(), QWidgetPrivate::childAt_helper(), QMacStyle::drawControl(), QToolBarAreaLayout::fitLayout(), qt_mac_unregister_widget(), QToolBarAreaLayout::restoreState(), QWidget::showFullScreen(), toolbarInUnifiedToolBar(), and QMainWindowLayout::usesHIToolBar().


The documentation for this class was generated from the following files: