Qt Toolkit - QMainWindow Class

# QMainWindow Class Reference

The QMainWindow class provides a typical application window, with a menu bar, some tool bars and a status bar. More...

`#include <qmainwindow.h>`

Inherits QWidget.

List of all member functions.

## Public Members

- QMainWindow ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )
- ~QMainWindow ()
- QMenuBar* menuBar () const
- QStatusBar* statusBar () const
- QToolTipGroup* toolTipGroup () const
- virtual void setCentralWidget ( QWidget * )
- QWidget* centralWidget () const
- enum ToolBarDock { Unmanaged, TornOff, Top, Bottom, Right, Left }
- void setDockEnabled ( ToolBarDock dock, bool enable )
- bool isDockEnabled ( ToolBarDock dock ) const
- void addToolBar ( QToolBar *, const char * label, ToolBarDock = Top, bool newLine = FALSE )
- void removeToolBar ( QToolBar * )
- virtual void show ()
- bool rightJustification () const
- bool usesBigPixmaps () const
- virtual bool eventFilter ( QObject *, QEvent * )

## Public Slots

- void setRightJustification ( bool )
- void setUsesBigPixmaps ( bool )

## Signals

- void pixmapSizeChanged ( bool )

## Protected Members

- virtual void paintEvent ( QPaintEvent * )
- virtual bool event ( QEvent * )

## Protected Slots

- void setUpLayout ()

## Detailed Description

The QMainWindow class provides a typical application window, with a menu bar, some tool bars and a status bar.

In addition, you need the large central widget, which you supply and tell QMainWindow about using setCentralWidget(), and perhaps a few tool bars, which you can add using addToolBar().

The central widget is not touched by QMainWindow. QMainWindow manages its geometry, and that is all. For example, the application/application.cpp exmple (an editor) sets a QMultiLineEdit to be the central widget.

QMainWindow automatically detects the creation of a menu bar or status bar if you specify the QMainWindow as parent, or you can use the provided menuBar() and statusBar() functions. menuBar() and statusBar() create a suitable widget if one doesn't exist, and updates the window's layout to make space.

QMainWindow also provides a QToolTipGroup connected to the status bar. toolTipGroup() provides access to the QToolTipGroup, but there is no way to set the tool tip group.

By default, QMainWindow only allows toolbars above the central widget. You can use setDockEnabled() to allow toolbars in other docks (a dock is a place where toolbars can stay). Currently, only `Top, Left, Right` and `Bottom` are meaningful.

Several functions let you change the appearance of a QMainWindow globally: setRightJustification() determines whether QMainWindow should ensure that the toolbars fill the available space, setUsesBigPixmaps() determines whether QToolButton (and other classes) should draw small or large pixmaps (see QIconSet for more about that).

The current release of QMainWindow does not provide draggable toolbars. This feature is planned for inclusion in one of the next releases.

See also: QToolBar, QStatusBar, QMenuBar, QToolTipGroup and QDialog.

Examples: application/application.cpp

## Member Function Documentation

### QMainWindow::QMainWindow ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )

Constructs an empty main window.

### QMainWindow::~QMainWindow ()

Destroys the object and frees any allocated resources.

### void QMainWindow::addToolBar ( QToolBar * toolBar, const char * label, ToolBarDock edge = Top, bool nl = FALSE )

Adds toolbar to this the edge window of this window.

### QWidget * QMainWindow::centralWidget () const

Returns a pointer to the main child of this main widget. The main child is the big widget around which the tool bars are arranged.

See also: setCentralWidget().

### bool QMainWindow::event ( QEvent * e ) `[virtual protected]`

Monitors events to ensure layout is updated.

Reimplemented from QObject.

### bool QMainWindow::eventFilter ( QObject * o, QEvent * e ) `[virtual]`

Monitors events to ensure layout is updated.

Reimplemented from QObject.

### bool QMainWindow::isDockEnabled ( ToolBarDock dock ) const

Returns TRUE if dock is enabled, or FALSE if it is not.

See also: setDockEnabled().

### QMenuBar * QMainWindow::menuBar () const

Returns the menu bar for this window. If there isn't any, menuBar() creates an empty menu bar on the fly.

See also: statusBar().

Examples: application/application.cpp

### void QMainWindow::paintEvent ( QPaintEvent * ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

### void QMainWindow::pixmapSizeChanged ( bool ) `[signal]`

This signal is called whenever the setUsesBigPixmaps() is called with a value which is different from the current setting. All relevant widgets must connect to this signal.

### void QMainWindow::removeToolBar ( QToolBar * toolBar )

Removes toolBar from this main window, if toolBar is non-null and known by this main window.

### bool QMainWindow::rightJustification () const

Returns TRUE if this main windows right-justifies its toolbars, and FALSE if it uses a ragged right edge.

The default is to use a ragged right edge.

("Right edge" sometimes means "bottom edge".)

See also: setRightJustification().

### void QMainWindow::setCentralWidget ( QWidget * w ) `[virtual]`

Sets the central widget for this window to w. The centail widget is the one around which the toolbars etc. are arranged.

Examples: application/application.cpp

### void QMainWindow::setDockEnabled ( ToolBarDock dock, bool enable )

Sets dock to be available if enable is TRUE, and not available if enable is FALSE.

The user can drag a toolbar to any enabled dock.

### void QMainWindow::setRightJustification ( bool enable ) `[slot]`

Sets this main window to expand its toolbars to fill all available space if enable is TRUE, and to give the toolbars just the space they need if enable is FALSE.

The default is FALSE.

See also: rightJustification();.

### void QMainWindow::setUpLayout () `[protected slot]`

Sets up the geometry management of this window. Called automatically when needed, so you should never need to call this.

### void QMainWindow::setUsesBigPixmaps ( bool enable ) `[slot]`

Sets tool buttons in this main windows to use big pixmaps if enable is TRUE, and small pixmaps if enable is FALSE.

The default is FALSE.

Tool buttons and other interested widgets are responsible for reading the correct state on startup, and for connecting to this widget's pixmapSizeChanged() signal.

See also: QToolButton::setUsesBigPixmap().

### void QMainWindow::show () `[virtual]`

Reimplemented for internal reasons; the API is not affected.

Examples: application/application.cpp

Reimplemented from QWidget.

### QStatusBar * QMainWindow::statusBar () const

Returns the status bar for this window. If there isn't any, statusBar() creates an empty status bar on the fly, and if necessary a tool tip group too.

See also: setMenuBar(), statusBar() and toolTipGroup().

Examples: application/application.cpp

### QToolTipGroup * QMainWindow::toolTipGroup () const

Returns the tool tip group for this window. If there isn't any, menuBar() creates an empty tool tip group on the fly.

See also: menuBar() and statusBar().

### bool QMainWindow::usesBigPixmaps () const

Returns the state last set by setUsesBigPixmaps(). The initial state is FALSE.

See also: setUsesBigPixmaps();.

Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):

This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.

It was generated from the following files:

- qmainwindow.h: 1998/08/19
- qmainwindow.cpp: 1998/11/01