Qt logo

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

Public Slots

Signals

Protected Members

Protected Slots


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

The QMainWindow allows by default toolbars in all docking areas. You can use setDockEnabled() to enable and disable docking areas for toolbars. Currently, only Top, Left, Right, Bottom and Hidden are meaningful.

Several functions let you change the appearance of a QMainWindow globally:

Toolbars can be dragged by the user into each enabled docking area and inside each docking area to change the order of the toolbars there. This feature can be enabled and disabled using setToolBarsMovable(). By default this feature is enabled. If the Hidden dock is enabled the user can hide/show a toolbar with a click on the toolbar handle. The handles of all hidden toolbars are drawn below the menu bar in one row, and if the user moves the mouse cursor onto such a handle, the label of the toolbar is displayed in a tool tip (see QToolBar::label()).

An application with multiple toolbars can choose to save the current toolbar layout in order to restore it in the next session. To do so, use getLocation() on each toolbar, store the data and restore the layout using moveToolBar() on each toolbar again. When restoring, ensure to move the toolbars in exactly the same order in which you got the information.

For multidocument interfaces (MDI), use a QWorkspace as central widget.

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

Examples: mainlyQt/editor.cpp


Member Type Documentation

QMainWindow::ToolBarDock

Each toolbar can be in one of the following positions:

Other values are also defined for future expansion.


Member Function Documentation

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

Constructs an empty main window.

QMainWindow::~QMainWindow ()

Destructs the object and frees any allocated resources.

void QMainWindow::addToolBar ( QToolBar * toolBar, ToolBarDock edge = Top, bool newLine = FALSE )

Adds toolBar to this the end of edge and makes it start a new line of tool bars if nl is TRUE.

If toolBar is already managed by some main window, it is first removed from that window.

void QMainWindow::addToolBar ( QToolBar * toolBar, const QString & label, ToolBarDock edge = Top, bool newLine = FALSE )

Adds toolBar to this the end of edge, labelling it label and makes it start a new line of tool bars if newLine is TRUE.

If toolBar is already managed by some main window, it is first removed from that 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().

Examples: qfd/qfd.cpp

void QMainWindow::childEvent ( QChildEvent * e ) [virtual protected]

Monitors events to ensure layout is updated.

Reimplemented from QObject.

void QMainWindow::endMovingToolbar ( QToolBar * toolbar ) [signal]

This signal is emitted if the toolbar has been moved by the user and he/she released the mouse button now, so he/she stopped the moving.

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

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QObject.

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

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QObject.

QMainWindow::ToolBarDock QMainWindow::findDockArea( const QPoint & pos, QRect & rect, QToolBar * tb, int & ipos, QToolBar *& covering ) [protected]

For internal use only.

bool QMainWindow::getLocation ( QToolBar * tb, ToolBarDock & dock, int & index, bool & nl ) const

Finds and gives back the dock and the index there of the toolbar tb. dock is set to the dock of the mainwindow in which tb is and index is set to the position of the toolbar in this dock. If the toolbar has a new line, nl is set to TRUE, else to FALSE.

This method returns TRUE if the information could be found out, otherwise FALSE (e.g. because the toolbar tb was not found in this mainwindow).

bool QMainWindow::isDockEnabled ( ToolBarDock dock ) const

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

See also: setDockEnabled().

bool QMainWindow::isDockEnabled ( QToolBar * tb, ToolBarDock dock ) const

Returns TRUE if dock is enabled for the toolbar tb , 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().

QSize QMainWindow::minimumSizeHint () const [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QMainWindow::moveToolBar ( QToolBar * toolBar, ToolBarDock edge = Top )

Moves toolBar to this the end of edge.

If toolBar is already managed by some main window, it is moved from that window to this.

void QMainWindow::moveToolBar ( QToolBar * toolBar, ToolBarDock edge, QToolBar * relative, bool after ) [protected]

Moves toolBar before the tollbar relative if after is FALSE, or after relative if after is TRUE.

If toolBar is already managed by some main window, it is moved from that window to this.

void QMainWindow::moveToolBar ( QToolBar * toolBar, ToolBarDock edge, bool nl, int index )

Moves toolBar to the position index of edge.

If toolBar is already managed by some main window, it is moved from that window to this.

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.

void QMainWindow::resizeEvent ( QResizeEvent * ) [virtual protected]

Monitors events to ensure layout is updated.

Reimplemented from QWidget.

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 central widget is the one around which the toolbars etc. are arranged.

void QMainWindow::setDockEnabled ( ToolBarDock dock, bool enable ) [virtual]

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::setDockEnabled ( QToolBar * tb, ToolBarDock dock, bool enable )

Sets dock to be available for the toolbar tb if enable is TRUE, and not available if enable is FALSE.

The user can drag the toolbar to any enabled dock.

void QMainWindow::setRightJustification ( bool enable ) [virtual slot]

Sets this main window to right-justifies its toolbars if enable is TRUE. If enable is FALSE, only stretchable toolbars are expanded, while non-stretchable toolbars get just the space they need. Given that most toolbars are not stretchable, this usually results in a ragged right edge.

The default is FALSE.

See also: rightJustification() and QToolBar::setStretchable().

void QMainWindow::setToolBarsMovable ( bool enable ) [slot]

Sets the toolbars to be movable if enable is TRUE, or static otherwise.

Movable toolbars can be dragged around between and within the different toolbar docks by the user.

The default is TRUE.

See also: setDockEnabled() and toolbarsMovable().

void QMainWindow::setUpLayout () [virtual 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 ) [virtual 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::setUsesTextLabel ( bool enable ) [slot]

Sets tool buttons in this main windows to use text labels if enable is TRUE, and no text labels otherwise.

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

See also: QToolButton::setUsesTextLabel().

void QMainWindow::show () [virtual]

Reimplemented for internal reasons; the API is not affected.

Examples: themes/main.cpp mainlyQt/editor.cpp application/main.cpp i18n/main.cpp scribble/main.cpp qfd/qfd.cpp addressbook/main.cpp qfileiconview/main.cpp

Reimplemented from QWidget.

QSize QMainWindow::sizeHint () const [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QMainWindow::startMovingToolbar ( QToolBar * toolbar ) [signal]

This signal is emitted when the toolbar starts moving because the user started dragging it.

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: menuBar() and toolTipGroup().

Examples: qfd/qfd.cpp

void QMainWindow::styleChange ( QStyle & old ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

QList<QToolBarQMainWindow::toolBars ( ToolBarDock dock ) const

Returns a list of all toolbars which are placed in dock.

bool QMainWindow::toolBarsMovable () const

Returns whether or not the toolbars of this main window are movable.

See also: setToolbarsMovable().

QToolTipGroup * QMainWindow::toolTipGroup () const

Returns the tool tip group for this window. If there isn't any, toolTipGroup() 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();.

bool QMainWindow::usesTextLabel () const

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

See also: setUsesTextLabel();.

void QMainWindow::usesTextLabelChanged ( bool ) [signal]

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

void QMainWindow::whatsThis () [slot]

Enters What's This? question mode and returns immediately.

This is the same as QWhatsThis::enterWhatsThisMode(), but as a slot of of a main window object. This way it can be easily used for popup menus as in the code fragment:

    QPopupMenu * help = new QPopupMenu( this );
    help->insertItem( "What's &This", this , SLOT(whatsThis()), SHIFT+Key_F1);

See also: QWhatsThis::enterWhatsThisMode().


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


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


Copyright İ 2000 Troll TechTrademarks
Qt version 2.1.0 (pre-release)