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.
Type | Name | READ | WRITE | Options |
---|---|---|---|---|
bool | rightJustification | rightJustification | setRightJustification | |
bool | usesBigPixmaps | usesBigPixmaps | setUsesBigPixmaps | |
bool | usesTextLabel | usesTextLabel | setUsesTextLabel | |
bool | toolBarsMovable | toolBarsMovable | setToolBarsMovable | |
bool | opaqueMoving | opaqueMoving | setOpaqueMoving |
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 Minimized
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 Minimized
dock is enabled the user
can hide(minimize)/show(restore) a toolbar with a click on the toolbar handle. The handles of
all minimized 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()). So if you enable the Minimized dock,
you should specify a meaningful label for each toolbar.
Normally toolbars are moved transparently (this means while the user drags one, a rectangle is drawn on the screen). With setOpaqueMoving() it's possible to switch between opaque and transparent moving of toolbars.
The main window's menubar is static (on the top) by default. If you want a movable menubar, create a QMenuBar as stretchable widget inside its own movable toolbar and restrict this toolbar to only live within the Top or Bottom dock:
QToolBar *tb = new QToolBar( this ); addToolBar( tb, tr( "Menubar" ), Top, FALSE ); QMenuBar *mb = new QMenuBar( tb ); mb->setFrameStyle( QFrame::NoFrame ); tb->setStretchableWidget( mb ); setDockEnabled( tb, Left, FALSE ); setDockEnabled( tb, Right, FALSE );
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 multi-document interfaces (MDI), use a QWorkspace as central widget.
See also QToolBar, QStatusBar, QMenuBar, QToolTipGroup and QDialog.
Examples: mainlyQt/editor.cpp
Top
- above the central widget, below the menubar.
Bottom
- below the central widget, above the status bar.
Left
- to the left of the central widget.
Right
- to the left of the central widget.
Minimized
- the toolbar is not shown - all handles of minimized toolbars
are drawn in one row below the menu bar.
Other values are also defined for future expansion.
Constructs an empty main window.
Destructs the object and frees any allocated resources.
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.
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.
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
[virtual protected]
Monitors events to ensure layout is updated.
Reimplemented from QObject.
[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.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QObject.
[virtual]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QObject.
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).
Returns TRUE if dock is enabled, or FALSE if it is not.
See also setDockEnabled().
Returns TRUE if dock is enabled for the toolbar tb , or FALSE if it is not.
See also setDockEnabled().
Returns TRUE, if rightclicking on an empty space on a toolbar dock or rightclicking on a toolbar handle opens a popup menu which allows lining up toolbars and hiding/showing toolbars.
See also setDockEnabled() and lineUpToolBars().
As toolbars can be freely moved inside docks, it's possible to line them up nicely with this method to get rid of all the unused space. If keepNewLines is TRUE, all toolbars stay in the line in which they are, else they are packed together as compact as possible.
The method only works if movable() returns TRUE.
Returns the menu bar for this window. If there isn't any, menuBar() creates an empty menu bar on the fly.
See also statusBar().
[virtual]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
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.
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.
Returns whether the toolbars of the mainwindow can be moved opaque or transparent.
See also setOpaqueMoving().
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[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.
Removes toolBar from this main window's docking area, if toolBar is non-null and known by this main window.
[virtual protected]
Monitors events to ensure layout is updated.
Reimplemented from QWidget.
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().
[virtual]
Sets the central widget for this window to w. The central widget is the one around which the toolbars etc. are arranged.
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.
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.
[slot]
When passing TRUE for b here, rightclicking on an empty space on a toolbar dock or rightclicking on a toolbar handle opens a popup menu which allows lining up toolbars and hiding/showing toolbars.
See also lineUpToolBars() and isDockMenuEnabled().
[slot]
If you set b to TRUE, the use can move the toolbars opaque, otherwise this is done transparent. This setting makes only sense, if toolBarsMovable() is set to TRUE.
See also setToolbarsMovable().
[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(), QToolBar::setVerticalStretchable() and QToolBar::setHorizontalStretchable().
[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. By default toolbars are moved transparent, but this setting can be changed by setOpaqueMoving().
The default is TRUE.
See also setDockEnabled(), toolBarsMovable() and setOpaqueMoving().
[virtual protected slot]
Sets up the geometry management of this window. Called automatically when needed, so you should never need to call this.
[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().
[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().
[virtual]
Reimplemented for internal reasons; the API is not affected.
Examples: action/main.cpp themes/main.cpp mainlyQt/editor.cpp application/main.cpp helpviewer/main.cpp i18n/main.cpp fileiconview/main.cpp scribble/main.cpp qfd/qfd.cpp addressbook/main.cpp mdi/main.cpp
Reimplemented from QWidget.
[virtual]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[signal]
This signal is emitted when the toolbar starts moving because the user started dragging it.
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
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[signal]
This signal is emitted when the toolbar has changed its position. This means it has been moved to another dock or inside the dock.
See also getLocation().
Returns whether or not the toolbars of this main window are movable.
See also setToolBarsMovable().
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().
Returns the state last set by setUsesBigPixmaps(). The initial state is FALSE.
See also setUsesBigPixmaps();.
Returns the state last set by setUsesTextLabel(). The initial state is FALSE.
See also setUsesTextLabel();.
[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.
[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.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
Copyright İ 2000 Trolltech | Trademarks | Qt version 2.2.1
|