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.

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: 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, constchar*name=0, WFlagsf=WType_TopLevel)

Constructs an empty main window.

QMainWindow::~QMainWindow()

Destroys the object and frees any allocated resources.

voidQMainWindow::addToolBar(QToolBar*toolBar, ToolBarDockedge=Top, boolnewLine=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.

voidQMainWindow::addToolBar(QToolBar*toolBar, constQString&label, ToolBarDockedge=Top, boolnewLine=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

voidQMainWindow::childEvent(QChildEvent*e) [virtualprotected]

Monitors events to ensure layout is updated.

Reimplemented from QObject.

boolQMainWindow::event(QEvent*e) [virtualprotected]

Monitors events to ensure layout is updated.

Reimplemented from QObject.

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

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QObject.

boolQMainWindow::isDockEnabled(ToolBarDockdock)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().

voidQMainWindow::moveToolBar(QToolBar*toolBar, ToolBarDockedge=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 and set to not start a new line.

voidQMainWindow::paintEvent(QPaintEvent*) [virtualprotected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

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

voidQMainWindow::removeToolBar(QToolBar*toolBar)

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

voidQMainWindow::resizeEvent(QResizeEvent*) [virtualprotected]

Monitors events to ensure layout is updated.

Reimplemented from QWidget.

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

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

voidQMainWindow::setDockEnabled(ToolBarDockdock, boolenable) [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.

voidQMainWindow::setRightJustification(boolenable) [virtualslot]

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

voidQMainWindow::setUpLayout() [virtualprotected slot]

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

voidQMainWindow::setUsesBigPixmaps(boolenable) [virtualslot]

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

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

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

voidQMainWindow::styleChange(QStyle&old) [virtualprotected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

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

boolQMainWindow::usesBigPixmaps()const

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

See also: setUsesBigPixmaps();.

voidQMainWindow::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-99 Troll Tech, all rights reserved.


Copyright 1999 Troll TechTrademarks
Qt version 2.0.2