Eneboo - Documentación para desarrolladores
|
The QMainWindow class provides a main application window, with a menu bar, dock windows (e.g. for toolbars), and a status bar. Más...
#include <qmainwindow.h>
The QMainWindow class provides a main application window, with a menu bar, dock windows (e.g. for toolbars), and a status bar.
Main windows are most often used to provide menus, toolbars and a status bar around a large central widget, such as a text edit, drawing canvas or QWorkspace (for MDI applications). QMainWindow is usually subclassed since this makes it easier to encapsulate the central widget, menus and toolbars as well as the window's state. Subclassing makes it possible to create the slots that are called when the user clicks menu items or toolbar buttons. You can also create main windows using Qt Designer. We'll briefly review adding menu items and toolbar buttons then describe the facilities of QMainWindow itself.
QMainWindow *mw = new QMainWindow; QTextEdit *edit = new QTextEdit( mw, "editor" ); edit->setFocus(); mw->setCaption( "Main Window" ); mw->setCentralWidget( edit ); mw->show();
QMainWindows may be created in their own right as shown above. The central widget is set with setCentralWidget(). Popup menus can be added to the default menu bar, widgets can be added to the status bar, toolbars and dock windows can be added to any of the dock areas.
application/main.cpp ApplicationWindow show
In the extract above ApplicationWindow is a subclass of QMainWindow that we must write for ourselves; this is the usual approach to using QMainWindow. (The source for the extracts in this description are taken from application/main.cpp, application/application.cpp, action/main.cpp, and action/application.cpp )
When subclassing we add the menu items and toolbars in the subclass's constructor. If we've created a QMainWindow instance directly we can add menu items and toolbars just as easily by passing the QMainWindow instance as the parent instead of the this pointer.
application/application.cpp help = new about
Here we've added a new menu with one menu item. The menu has been inserted into the menu bar that QMainWindow provides by default and which is accessible through the menuBar() function. The slot will be called when the menu item is clicked.
application/application.cpp fileTools setLabel QToolButton open file
This extract shows the creation of a toolbar with one toolbar button. QMainWindow supplies four dock areas for toolbars. When a toolbar is created as a child of a QMainWindow (or derived class) instance it will be placed in a dock area (the Top
dock area by default). The slot will be called when the toolbar button is clicked. Any dock window can be added to a dock area either using addDockWindow(), or by creating a dock window with the QMainWindow as the parent.
application/application.cpp editor statusBar
Having created the menus and toolbar we create an instance of the large central widget, give it the focus and set it as the main window's central widget. In the example we've also set the status bar, accessed via the statusBar() function, to an initial message which will be displayed for two seconds. Note that you can add additional widgets to the status bar, for example labels, to show further status information. See the QStatusBar documentation for details, particularly the addWidget() function.
Often we want to synchronize a toolbar button with a menu item. For example, if the user clicks a 'bold' toolbar button we want the 'bold' menu item to be checked. This synchronization can be achieved automatically by creating actions and adding the actions to the toolbar and menu.
action/application.cpp QAction * fileOpen fileOpenAction choose
Here we create an action with an icon which will be used in any menu and toolbar that the action is added to. We've also given the action a menu name, '&Open', and a keyboard shortcut. The connection that we have made will be used when the user clicks either the menu item or the toolbar button.
action/application.cpp QPopupMenu * file menuBar fileOpen
The extract above shows the creation of a popup menu. We add the menu to the QMainWindow's menu bar and add our action.
action/application.cpp QToolBar * fileTool OpenAction
Here we create a new toolbar as a child of the QMainWindow and add our action to the toolbar.
We'll now explore the functionality offered by QMainWindow.
The main window will take care of the dock areas, and the geometry of the central widget, but all other aspects of the central widget are left to you. 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. The functions menuBar() and statusBar() create a suitable widget if one doesn't exist, and update the window's layout to make space.
QMainWindow provides a QToolTipGroup connected to the status bar. The function toolTipGroup() provides access to the default QToolTipGroup. It isn't possible to set a different tool tip group.
New dock windows and toolbars can be added to a QMainWindow using addDockWindow(). Dock windows can be moved using moveDockWindow() and removed with removeDockWindow(). QMainWindow allows default dock window (toolbar) docking in all its dock areas (Top
, Left
, Right
, Bottom
). You can use setDockEnabled() to enable and disable docking areas for dock windows. When adding or moving dock windows you can specify their 'edge' (dock area). The currently available edges are: Top
, Left
, Right
, Bottom
, Minimized
(effectively a 'hidden' dock area) and TornOff
(floating). See Qt::Dock for an explanation of these areas. Note that the *ToolBar functions are included for backward compatibility; all new code should use the *DockWindow functions. QToolbar is a subclass of QDockWindow so all functions that work with dock windows work on toolbars in the same way.
dwm If the user clicks the close button, then the dock window is hidden. A dock window can be hidden or unhidden by the user by right clicking a dock area and clicking the name of the relevant dock window on the pop up dock window menu. This menu lists the names of every dock window; visible dock windows have a tick beside their names. The dock window menu is created automatically as required by createDockWindowMenu(). Since it may not always be appropriate for a dock window to appear on this menu the setAppropriate() function is used to inform the main window whether or not the dock window menu should include a particular dock window. Double clicking a dock window handle (usually on the left-hand side of the dock window) undocks (floats) the dock window. Double clicking a floating dock window's titlebar will dock the floating dock window. (See also {QMainWindow::DockWindows}.)
Some functions change the appearance of a QMainWindow globally: QDockWindow::setHorizontalStretchable() and QDockWindow::setVerticalStretchable() are used to make specific dock windows or toolbars stretchable. setUsesBigPixmaps() is used to set whether tool buttons should draw small or large pixmaps (see QIconSet for more information). setUsesTextLabel() is used to set whether tool buttons should display a textual label in addition to pixmaps (see QToolButton for more information).
The user can drag dock windows into any enabled docking area. Dock windows can also be dragged within a docking area, for example to rearrange the order of some toolbars. Dock windows can also be dragged outside any docking area (undocked or 'floated'). Being able to drag dock windows can be enabled (the default) and disabled using setDockWindowsMovable().
The Minimized
edge is a hidden dock area. If this dock area is enabled the user can hide (minimize) a dock window or show (restore) a minimized dock window by clicking the dock window handle. If the user hovers the mouse cursor over one of the handles, the caption of the dock window is displayed in a tool tip (see QDockWindow::caption() or QToolBar::label()), so if you enable the Minimized
dock area, it is best to specify a meaningful caption or label for each dock window. To minimize a dock window programmatically use moveDockWindow() with an edge of Minimized
.
Dock windows are moved transparently by default, i.e. during the drag an outline rectangle is drawn on the screen representing the position of the dock window as it moves. If you want the dock window to be shown normally whilst it is moved use setOpaqueMoving().
The location of a dock window, i.e. its dock area and position within the dock area, can be determined by calling getLocation(). Movable dock windows can be lined up to minimize wasted space with lineUpDockWindows(). Pointers to the dock areas are available from topDock(), leftDock(), rightDock() and bottomDock(). A customize menu item is added to the pop up dock window menu if isCustomizable() returns TRUE; it returns FALSE by default. Reimplement isCustomizable() and customize() if you want to offer this extra menu item, for example, to allow the user to change settings relating to the main window and its toolbars and dock windows.
The main window's menu bar is fixed (at the top) by default. If you want a movable menu bar, create a QMenuBar as a stretchable widget inside its own movable dock window and restrict this dock window to only live within the Top
or Bottom
dock:
QToolBar *tb = new QToolBar( this ); addDockWindow( 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 dock windows can choose to save the current dock window layout in order to restore it later, e.g. in the next session. You can do this by using the streaming operators for QMainWindow.
To save the layout and positions of all the dock windows do this:
QFile file( filename ); if ( file.open( IO_WriteOnly ) ) { QTextStream stream( &file ); stream << *mainWindow; file.close(); }
To restore the dock window positions and sizes (normally when the application is next started), do following:
QFile file( filename ); if ( file.open( IO_ReadOnly ) ) { QTextStream stream( &file ); stream >> *mainWindow; file.close(); }
The QSettings class can be used in conjunction with the streaming operators to store the application's settings.
QMainWindow's management of dock windows and toolbars is done transparently behind-the-scenes by QDockArea.
For multi-document interfaces (MDI), use a QWorkspace as the central widget.
Adding dock windows, e.g. toolbars, to QMainWindow's dock areas is straightforward. If the supplied dock areas are not sufficient for your application we suggest that you create a QWidget subclass and add your own dock areas (see QDockArea) to the subclass since QMainWindow provides functionality specific to the standard dock areas it provides.
Right-clicking a dock area will pop-up the dock window menu (createDockWindowMenu() is called automatically). When called in code you can specify what items should appear on the menu with this enum.
OnlyToolBars The menu will list all the toolbars, but not any other dock windows.
NoToolBars The menu will list dock windows but not toolbars.
AllDockWindows The menu will list all toolbars and other dock windows. (This is the default.)
Constructs an empty main window. The parent, name and widget flags f, are passed on to the QWidget constructor.
By default, the widget flags are set to WType_TopLevel
rather than 0 as they are with QWidget. If you don't want your QMainWindow to be a top level widget then you will need to set f to 0.
QMainWindow::~QMainWindow | ( | ) |
Destroys the object and frees any allocated resources.
QMainWindow::~QMainWindow | ( | ) |
void QMainWindow::addDockWindow | ( | QDockWindow * | dockWindow, |
Dock | edge = DockTop , |
||
bool | newLine = FALSE |
||
) | [virtual] |
Adds dockWindow to the edge dock area.
If newLine is FALSE (the default) then the dockWindow is added at the end of the edge. For vertical edges the end is at the bottom, for horizontal edges (including Minimized
) the end is at the right. If newLine is TRUE a new line of dock windows is started with dockWindow as the first (left-most and top-most) dock window.
If dockWindow is managed by another main window, it is first removed from that window.
virtual void QMainWindow::addDockWindow | ( | QDockWindow * | , |
Dock | = DockTop , |
||
bool | newLine = FALSE |
||
) | [virtual] |
virtual void QMainWindow::addDockWindow | ( | QDockWindow * | , |
const QString & | label, | ||
Dock | = DockTop , |
||
bool | newLine = FALSE |
||
) | [virtual] |
void QMainWindow::addDockWindow | ( | QDockWindow * | dockWindow, |
const QString & | label, | ||
Dock | edge = DockTop , |
||
bool | newLine = FALSE |
||
) | [virtual] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Adds dockWindow to the dock area with label label.
If newLine is FALSE (the default) the dockWindow is added at the end of the edge. For vertical edges the end is at the bottom, for horizontal edges (including Minimized
) the end is at the right. If newLine is TRUE a new line of dock windows is started with dockWindow as the first (left-most and top-most) dock window.
If dockWindow is managed by another main window, it is first removed from that window.
void QMainWindow::addToolBar | ( | QDockWindow * | w, |
const QString & | label, | ||
Dock | dock = DockTop , |
||
bool | newLine = FALSE |
||
) | [inline] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta.
void QMainWindow::addToolBar | ( | QDockWindow * | w, |
Dock | dock = DockTop , |
||
bool | newLine = FALSE |
||
) | [inline] |
void QMainWindow::addToolBar | ( | QDockWindow * | , |
Dock | = DockTop , |
||
bool | newLine = FALSE |
||
) |
void QMainWindow::addToolBar | ( | QDockWindow * | , |
const QString & | label, | ||
Dock | = DockTop , |
||
bool | newLine = FALSE |
||
) |
bool QMainWindow::appropriate | ( | QDockWindow * | dw | ) | const |
Returns TRUE if it is appropriate to include a menu item for the dw dock window in the dock window menu; otherwise returns FALSE.
The user is able to change the state (show or hide) a dock window that has a menu item by clicking the item.
Call setAppropriate() to indicate whether or not a particular dock window should appear on the popup menu.
bool QMainWindow::appropriate | ( | QDockWindow * | dw | ) | const |
QDockArea * QMainWindow::bottomDock | ( | ) | const |
Returns a pointer the Bottom
dock area
QDockArea* QMainWindow::bottomDock | ( | ) | const |
QWidget* QMainWindow::centralWidget | ( | ) | const |
QWidget * QMainWindow::centralWidget | ( | ) | const |
Returns a pointer to the main window's central widget.
The central widget is surrounded by the left, top, right and bottom dock areas. The menu bar is above the top dock area.
void QMainWindow::childEvent | ( | QChildEvent * | e | ) | [protected, virtual] |
Monitors events, recieved in e, to ensure the layout is updated.
Reimplementado de QObject.
void QMainWindow::childEvent | ( | QChildEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive child events.
Child events are sent to objects when children are inserted or removed.
Note that events with QEvent::type() QEvent::ChildInserted
are posted (with {QApplication::postEvent()}) to make sure that the child's construction is completed before this function is called.
If a child is removed immediately after it is inserted, the ChildInserted
event may be suppressed, but the ChildRemoved
event will always be sent. In such cases it is possible that there will be a ChildRemoved
event without a corresponding ChildInserted
event.
If you change state based on ChildInserted
events, call QWidget::constPolish(), or do
in functions that depend on the state. One notable example is QWidget::sizeHint().
Reimplementado de QObject.
QPopupMenu * QMainWindow::createDockWindowMenu | ( | DockWindows | dockWindows = AllDockWindows | ) | const |
Creates the dock window menu which contains all toolbars (if dockWindows is OnlyToolBars
), all dock windows (if dockWindows is NoToolBars
) or all toolbars and dock windows (if dockWindows is AllDockWindows
- the default).
This function is called internally when necessary, e.g. when the user right clicks a dock area (providing isDockMenuEnabled() returns TRUE). ### Qt 4.0 You can reimplement this function if you wish to customize the behaviour.
The menu items representing the toolbars and dock windows are checkable. The visible dock windows are checked and the hidden dock windows are unchecked. The user can click a menu item to change its state (show or hide the dock window).
The list and the state are always kept up-to-date.
Toolbars and dock windows which are not appropriate in the current context (see setAppropriate()) are not listed in the menu.
The menu also has a menu item for lining up the dock windows.
If isCustomizable() returns TRUE, a Customize menu item is added to the menu, which if clicked will call customize(). The isCustomizable() function we provide returns FALSE and customize() does nothing, so they must be reimplemented in a subclass to be useful.
QPopupMenu* QMainWindow::createDockWindowMenu | ( | DockWindows | dockWindows = AllDockWindows | ) | const |
void QMainWindow::customize | ( | ) | [virtual, slot] |
This function is called when the user clicks the Customize menu item on the dock window menu.
The customize menu item will only appear if isCustomizable() returns TRUE (it returns FALSE by default).
The function is intended, for example, to provide the user with a means of telling the application that they wish to customize the main window, dock windows or dock areas.
The default implementation does nothing and the Customize menu item is not shown on the right-click menu by default. If you want the item to appear then reimplement isCustomizable() to return TRUE, and reimplement this function to do whatever you want.
virtual void QMainWindow::customize | ( | ) | [virtual, slot] |
void QMainWindow::dockWindowPositionChanged | ( | QDockWindow * | ) | [signal] |
void QMainWindow::dockWindowPositionChanged | ( | QDockWindow * | dockWindow | ) | [signal] |
This signal is emitted when the dockWindow has changed its position. A change in position occurs when a dock window is moved within its dock area or moved to another dock area (including the Minimized
and TearOff
dock areas).
QPtrList<QDockWindow> QMainWindow::dockWindows | ( | Dock | dock | ) | const |
QPtrList<QDockWindow> QMainWindow::dockWindows | ( | ) | const |
QPtrList< QDockWindow > QMainWindow::dockWindows | ( | Dock | dock | ) | const |
Returns a list of all the dock windows which are in the dock dock area, regardless of their state.
For example, the DockTornOff
dock area may contain closed dock windows but these are returned along with the visible dock windows.
QPtrList< QDockWindow > QMainWindow::dockWindows | ( | ) | const |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns the list of dock windows which belong to this main window, regardless of which dock area they are in or what their state is, (e.g. irrespective of whether they are visible or not).
bool QMainWindow::dockWindowsMovable | ( | ) | const |
bool QMainWindow::dockWindowsMovable | ( | ) | const |
This is the main event handler; it handles event e. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.
The main event handler first passes an event through all event filters that have been installed. If none of the filters intercept the event, it calls one of the specialized event handlers.
Key press and release events are treated differently from other events. event() checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event() calls keyPressEvent().
This function returns TRUE if it is able to pass the event over to someone (i.e. someone wanted the event); otherwise returns FALSE.
Reimplementado de QWidget.
Filters events if this object has been installed as an event filter for the watched object.
In your reimplementation of this function, if you want to filter the event e, out, i.e. stop it being handled further, return TRUE; otherwise return FALSE.
Example:
class MyMainWindow : public QMainWindow { public: MyMainWindow( QWidget *parent = 0, const char *name = 0 ); protected: bool eventFilter( QObject *obj, QEvent *ev ); private: QTextEdit *textEdit; }; MyMainWindow::MyMainWindow( QWidget *parent, const char *name ) : QMainWindow( parent, name ) { textEdit = new QTextEdit( this ); setCentralWidget( textEdit ); textEdit->installEventFilter( this ); } bool MyMainWindow::eventFilter( QObject *obj, QEvent *ev ) { if ( obj == textEdit ) { if ( e->type() == QEvent::KeyPress ) { QKeyEvent *k = (QKeyEvent*)ev; qDebug( "Ate key press %d", k->key() ); return TRUE; } else { return FALSE; } } else { // pass the event on to the parent class return QMainWindow::eventFilter( obj, ev ); } }
Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.
Reimplementado de QObject.
Reimplementado en MainWindow.
Reimplementado de QObject.
Reimplementado en MainWindow.
bool QMainWindow::getLocation | ( | QDockWindow * | tb, |
Dock & | dock, | ||
int & | index, | ||
bool & | nl, | ||
int & | extraOffset | ||
) | const |
bool QMainWindow::getLocation | ( | QDockWindow * | dw, |
Dock & | dock, | ||
int & | index, | ||
bool & | nl, | ||
int & | extraOffset | ||
) | const |
Finds the location of the dock window dw.
If the dw dock window is found in the main window the function returns TRUE and populates the dock variable with the dw's dock area and the index with the dw's position within the dock area. It also sets nl to TRUE if the dw begins a new line (otherwise FALSE), and extraOffset with the dock window's offset.
If the dw dock window is not found then the function returns FALSE and the state of dock, index, nl and extraOffset is undefined.
If you want to save and restore dock window positions then use operator>>() and operator<<().
bool QMainWindow::hasDockWindow | ( | QDockWindow * | dw | ) |
Returns TRUE if dw is a dock window known to the main window; otherwise returns FALSE.
bool QMainWindow::hasDockWindow | ( | QDockWindow * | dw | ) |
void QMainWindow::hide | ( | ) | [virtual] |
Reimplementado de QWidget.
void QMainWindow::hide | ( | ) | [virtual] |
Hides the widget.
You almost never have to reimplement this function. If you need to do something after a widget is hidden, use hideEvent() instead.
Reimplementado de QWidget.
bool QMainWindow::isCustomizable | ( | ) | const [virtual] |
Returns TRUE if the dock area dock window menu includes the Customize menu item (which calls customize() when clicked). Returns FALSE by default, i.e. the popup menu will not contain a Customize menu item. You will need to reimplement this function and set it to return TRUE if you wish the user to be able to see the dock window menu.
virtual bool QMainWindow::isCustomizable | ( | ) | const [virtual] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns TRUE if dock area area is enabled, i.e. it can accept user dragged dock windows; otherwise returns FALSE.
bool QMainWindow::isDockEnabled | ( | QDockWindow * | tb, |
Dock | dock | ||
) | const |
bool QMainWindow::isDockEnabled | ( | QDockWindow * | tb, |
QDockArea * | area | ||
) | const |
bool QMainWindow::isDockEnabled | ( | QDockWindow * | tb, |
Dock | dock | ||
) | const |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns TRUE if dock area dock is enabled for the dock window tb; otherwise returns FALSE.
bool QMainWindow::isDockEnabled | ( | QDockWindow * | dw, |
QDockArea * | area | ||
) | const |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns TRUE if dock area area is enabled for the dock window dw; otherwise returns FALSE.
Returns TRUE if the dock dock area is enabled, i.e. it can accept user dragged dock windows; otherwise returns FALSE.
bool QMainWindow::isDockMenuEnabled | ( | ) | const |
bool QMainWindow::isDockMenuEnabled | ( | ) | const |
Returns TRUE, if the dock window menu is enabled; otherwise returns FALSE.
The menu lists the (appropriate()) dock windows (which may be shown or hidden), and has a "Line Up Dock Windows" menu item. It will also have a "Customize" menu item if isCustomizable() returns TRUE.
QDockArea * QMainWindow::leftDock | ( | ) | const |
Returns the Left
dock area
QDockArea* QMainWindow::leftDock | ( | ) | const |
void QMainWindow::lineUpDockWindows | ( | bool | keepNewLines = FALSE | ) |
void QMainWindow::lineUpDockWindows | ( | bool | keepNewLines = FALSE | ) |
This function will line up dock windows within the visible dock areas (Top
, Left
, Right
and Bottom
) as compactly as possible.
If keepNewLines is TRUE, all dock windows stay on their original lines. If keepNewLines is FALSE then newlines may be removed to achieve the most compact layout possible.
The method only works if dockWindowsMovable() returns TRUE.
void QMainWindow::lineUpToolBars | ( | bool | keepNewLines = FALSE | ) | [inline] |
void QMainWindow::lineUpToolBars | ( | bool | keepNewLines = FALSE | ) |
void QMainWindow::menuAboutToShow | ( | ) | [protected, slot] |
This slot is called from the aboutToShow() signal of the default dock menu of the mainwindow. The default implementation initializes the menu with all dock windows and toolbars in this slot. ### Qt 4.0 If you want to do small adjustments to the menu, you can do it in this slot; or you can reimplement createDockWindowMenu().
void QMainWindow::menuAboutToShow | ( | ) | [protected, slot] |
QMenuBar* QMainWindow::menuBar | ( | ) | const |
QMenuBar * QMainWindow::menuBar | ( | ) | const |
Returns the menu bar for this window.
If there isn't one, then menuBar() creates an empty menu bar.
virtual void QMainWindow::moveDockWindow | ( | QDockWindow * | , |
Dock | = DockTop |
||
) | [virtual] |
virtual void QMainWindow::moveDockWindow | ( | QDockWindow * | , |
Dock | , | ||
bool | nl, | ||
int | index, | ||
int | extraOffset = -1 |
||
) | [virtual] |
void QMainWindow::moveDockWindow | ( | QDockWindow * | dockWindow, |
Dock | edge = DockTop |
||
) | [virtual] |
Moves dockWindow to the end of the edge.
For vertical edges the end is at the bottom, for horizontal edges (including Minimized
) the end is at the right.
If dockWindow is managed by another main window, it is first removed from that window.
void QMainWindow::moveDockWindow | ( | QDockWindow * | dockWindow, |
Dock | edge, | ||
bool | nl, | ||
int | index, | ||
int | extraOffset = -1 |
||
) | [virtual] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Moves dockWindow to position index within the edge dock area.
Any dock windows with positions index or higher have their position number incremented and any of these on the same line are moved right (down for vertical dock areas) to make room.
If nl is TRUE, a new dock window line is created below the line in which the moved dock window appears and the moved dock window, with any others with higher positions on the same line, is moved to this new line.
The extraOffset is the space to put between the left side of the dock area (top side for vertical dock areas) and the dock window. (This is mostly used for restoring dock windows to the positions the user has dragged them to.)
If dockWindow is managed by another main window, it is first removed from that window.
void QMainWindow::moveToolBar | ( | QDockWindow * | w, |
Dock | dock = DockTop |
||
) | [inline] |
void QMainWindow::moveToolBar | ( | QDockWindow * | w, |
Dock | dock, | ||
bool | nl, | ||
int | index, | ||
int | extraOffset = -1 |
||
) | [inline] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta.
void QMainWindow::moveToolBar | ( | QDockWindow * | , |
Dock | = DockTop |
||
) |
void QMainWindow::moveToolBar | ( | QDockWindow * | , |
Dock | , | ||
bool | nl, | ||
int | index, | ||
int | extraOffset = -1 |
||
) |
bool QMainWindow::opaqueMoving | ( | ) | const |
bool QMainWindow::opaqueMoving | ( | ) | const |
void QMainWindow::paintEvent | ( | QPaintEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QCanvas do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::unite()). repaint() does not permit this optimization, so we suggest using update() when possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background. There are a couple of exceptions and QPaintEvent::erased() tells you whether the widget has been erased or not.
The background can be set using setBackgroundMode(), setPaletteBackgroundColor() or setBackgroundPixmap(). The documentation for setBackgroundMode() elaborates on the background; we recommend reading it.
Reimplementado de QWidget.
void QMainWindow::paintEvent | ( | QPaintEvent * | ) | [protected, virtual] |
Reimplementado de QWidget.
void QMainWindow::pixmapSizeChanged | ( | bool | ) | [signal] |
void QMainWindow::pixmapSizeChanged | ( | bool | t0 | ) | [signal] |
This signal is emitted whenever the setUsesBigPixmaps() is called with a value different to the current setting. All widgets that should respond to such changes, e.g. toolbar buttons, must connect to this signal.
void QMainWindow::removeDockWindow | ( | QDockWindow * | dockWindow | ) | [virtual] |
Removes dockWindow from the main window's docking area, provided dockWindow is non-null and managed by this main window.
virtual void QMainWindow::removeDockWindow | ( | QDockWindow * | ) | [virtual] |
void QMainWindow::removeToolBar | ( | QDockWindow * | w | ) | [inline] |
void QMainWindow::removeToolBar | ( | QDockWindow * | ) |
QDockArea * QMainWindow::rightDock | ( | ) | const |
Returns the Right
dock area
QDockArea* QMainWindow::rightDock | ( | ) | const |
bool QMainWindow::rightJustification | ( | ) | const |
bool QMainWindow::rightJustification | ( | ) | const |
void QMainWindow::setAppropriate | ( | QDockWindow * | dw, |
bool | a | ||
) | [virtual, slot] |
Use this function to control whether or not the dw dock window's caption should appear as a menu item on the dock window menu that lists the dock windows.
If a is TRUE then the dw will appear as a menu item on the dock window menu. The user is able to change the state (show or hide) a dock window that has a menu item by clicking the item; depending on the state of your application, this may or may not be appropriate. If a is FALSE the dw will not appear on the popup menu.
virtual void QMainWindow::setAppropriate | ( | QDockWindow * | dw, |
bool | a | ||
) | [virtual, slot] |
virtual void QMainWindow::setCentralWidget | ( | QWidget * | ) | [virtual] |
void QMainWindow::setCentralWidget | ( | QWidget * | w | ) | [virtual] |
Sets the central widget for this main window to w.
The central widget is surrounded by the left, top, right and bottom dock areas. The menu bar is above the top dock area.
void QMainWindow::setDockEnabled | ( | QDockWindow * | dw, |
Dock | dock, | ||
bool | enable | ||
) | [virtual] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. If enable is TRUE then users can dock the dw dock window in the dock area. If enable is FALSE users cannot dock the dw dock window in the dock area.
In general users can dock (drag) dock windows into any enabled dock area. Using this function particular dock areas can be enabled (or disabled) as docking points for particular dock windows.
virtual void QMainWindow::setDockEnabled | ( | QDockWindow * | tb, |
Dock | dock, | ||
bool | enable | ||
) | [virtual] |
If enable is TRUE then users can dock windows in the dock area. If enable is FALSE users cannot dock windows in the dock dock area.
Users can dock (drag) dock windows into any enabled dock area.
void QMainWindow::setDockMenuEnabled | ( | bool | b | ) | [virtual, slot] |
If b is TRUE, then right clicking on a dock window or dock area will pop up the dock window menu. If b is FALSE, right clicking a dock window or dock area will not pop up the menu.
The menu lists the (appropriate()) dock windows (which may be shown or hidden), and has a "Line Up Dock Windows" item. It will also have a "Customize" menu item if isCustomizable() returns TRUE.
virtual void QMainWindow::setDockMenuEnabled | ( | bool | ) | [virtual, slot] |
void QMainWindow::setDockWindowsMovable | ( | bool | enable | ) | [virtual, slot] |
virtual void QMainWindow::setDockWindowsMovable | ( | bool | ) | [virtual, slot] |
void QMainWindow::setOpaqueMoving | ( | bool | b | ) | [virtual, slot] |
virtual void QMainWindow::setOpaqueMoving | ( | bool | ) | [virtual, slot] |
void QMainWindow::setRightJustification | ( | bool | enable | ) | [virtual, slot] |
virtual void QMainWindow::setRightJustification | ( | bool | ) | [virtual, slot] |
void QMainWindow::setToolBarsMovable | ( | bool | ) | [slot] |
void QMainWindow::setToolBarsMovable | ( | bool | b | ) | [inline, slot] |
void QMainWindow::setUpLayout | ( | ) | [protected, virtual, slot] |
Sets up the geometry management of the window. It is called automatically when needed, so you shouldn't need to call it.
virtual void QMainWindow::setUpLayout | ( | ) | [protected, virtual, slot] |
virtual void QMainWindow::setUsesBigPixmaps | ( | bool | ) | [virtual, slot] |
void QMainWindow::setUsesBigPixmaps | ( | bool | enable | ) | [virtual, slot] |
virtual void QMainWindow::setUsesTextLabel | ( | bool | ) | [virtual, slot] |
void QMainWindow::setUsesTextLabel | ( | bool | enable | ) | [virtual, slot] |
void QMainWindow::show | ( | ) | [virtual] |
Shows the widget and its child widgets.
If its size or position has changed, Qt guarantees that a widget gets move and resize events just before it is shown.
You almost never have to reimplement this function. If you need to change some settings before a widget is shown, use showEvent() instead. If you need to do some delayed initialization use polish().
Reimplementado de QWidget.
void QMainWindow::show | ( | ) | [virtual] |
Reimplementado de QWidget.
Shows the dock menu at the position globalPos. The menu lists the dock windows so that they can be shown (or hidden), lined up, and possibly customized. Returns TRUE if the menu is shown; otherwise returns FALSE.
If you want a custom menu, reimplement this function. You can create the menu from scratch or call createDockWindowMenu() and modify the result. ### Qt 4.0 The default implementation uses the dock window menu which gets created by createDockWindowMenu(). You can reimplement createDockWindowMenu() if you want to use your own specialized popup menu.
QStatusBar* QMainWindow::statusBar | ( | ) | const |
QStatusBar * QMainWindow::statusBar | ( | ) | const |
Returns this main window's status bar. If there isn't one, statusBar() creates an empty status bar, and if necessary a tool tip group too.
void QMainWindow::styleChange | ( | QStyle & | ) | [protected, virtual] |
This virtual function is called when the style of the widgets changes. oldStyle is the previous GUI style; you can get the new style from style().
Reimplement this function if your widget needs to know when its GUI style changes. You will almost certainly need to update the widget using update().
The default implementation updates the widget including its geometry.
Reimplementado de QWidget.
void QMainWindow::toolBarPositionChanged | ( | QToolBar * | ) | [signal] |
void QMainWindow::toolBarPositionChanged | ( | QToolBar * | t0 | ) | [signal] |
Returns a list of all the toolbars which are in the dock dock area, regardless of their state.
For example, the TornOff
dock area may contain closed toolbars but these are returned along with the visible toolbars.
bool QMainWindow::toolBarsMovable | ( | ) | const [inline] |
bool QMainWindow::toolBarsMovable | ( | ) | const |
QToolTipGroup * QMainWindow::toolTipGroup | ( | ) | const |
Returns this main window's tool tip group. If there isn't one, toolTipGroup() creates an empty tool tip group.
QToolTipGroup* QMainWindow::toolTipGroup | ( | ) | const |
QDockArea * QMainWindow::topDock | ( | ) | const |
Returns the Top
dock area
QDockArea* QMainWindow::topDock | ( | ) | const |
bool QMainWindow::usesBigPixmaps | ( | ) | const |
bool QMainWindow::usesBigPixmaps | ( | ) | const |
bool QMainWindow::usesTextLabel | ( | ) | const |
bool QMainWindow::usesTextLabel | ( | ) | const |
void QMainWindow::usesTextLabelChanged | ( | bool | t0 | ) | [signal] |
This signal is emitted whenever the setUsesTextLabel() is called with a value different to the current setting. All widgets that should respond to such changes, e.g. toolbar buttons, must connect to this signal.
void QMainWindow::usesTextLabelChanged | ( | bool | ) | [signal] |
void QMainWindow::whatsThis | ( | ) | [virtual, slot] |
Enters 'What's This?' mode and returns immediately.
This is the same as QWhatsThis::enterWhatsThisMode(), but implemented as a main window object's slot. This way it can easily be used for popup menus, for example:
QPopupMenu * help = new QPopupMenu( this ); help->insertItem( "What's &This", this , SLOT(whatsThis()), SHIFT+Key_F1);
virtual void QMainWindow::whatsThis | ( | ) | [virtual, slot] |
QTextStream & operator<< | ( | QTextStream & | ts, |
const QMainWindow & | mainWindow | ||
) | [related] |
Writes the layout (sizes and positions) of the dock windows in the dock areas of the QMainWindow mainWindow, including Minimized
and TornOff
dock windows, to the text stream ts.
This can be used, for example, in conjunction with QSettings to save the user's layout when the receives a closeEvent.
QTextStream & operator>> | ( | QTextStream & | ts, |
QMainWindow & | mainWindow | ||
) | [related] |
Reads the layout (sizes and positions) of the dock windows in the dock areas of the QMainWindow mainWindow from the text stream, ts, including Minimized
and TornOff
dock windows. Restores the dock windows and dock areas to these sizes and positions. The layout information must be in the format produced by operator<<().
This can be used, for example, in conjunction with QSettings to restore the user's layout.
QDockWindow [friend] |
QHideDock [friend] |
QMainWindowLayout [friend] |
QMenuBar [friend] |
QToolBar [friend] |
bool QMainWindow::dockWindowsMovable [read, write] |
whether the dock windows are movable
If TRUE (the default), the user will be able to move movable dock windows from one QMainWindow dock area to another, including the TearOff
area (i.e. where the dock window floats freely as a window in its own right), and the Minimized
area (where only the dock window's handle is shown below the menu bar). Moveable dock windows can also be moved within QMainWindow dock areas, i.e. to rearrange them within a dock area.
If FALSE the user will not be able to move any dock windows.
By default dock windows are moved transparently (i.e. only an outline rectangle is shown during the drag), but this setting can be changed with setOpaqueMoving().
bool QMainWindow::opaqueMoving [read, write] |
whether dock windows are moved opaquely
If TRUE the dock windows of the main window are shown opaquely (i.e. it shows the toolbar as it looks when docked) whilst it is being moved. If FALSE (the default) they are shown transparently, (i.e. as an outline rectangle).
bool QMainWindow::rightJustification [read, write] |
whether the main window right-justifies its dock windows
If disabled (the default), stretchable dock windows are expanded, and non-stretchable dock windows are given the minimum space they need. Since most dock windows are not stretchable, this usually results in an unjustified right edge (or unjustified bottom edge for a vertical dock area). If enabled, the main window will right-justify its dock windows.
bool QMainWindow::usesBigPixmaps [read, write] |
whether big pixmaps are enabled
If FALSE (the default), the tool buttons will use small pixmaps; otherwise big pixmaps will be used.
Tool buttons and other widgets that wish to respond to this setting are responsible for reading the correct state on startup, and for connecting to the main window's widget's pixmapSizeChanged() signal.
bool QMainWindow::usesTextLabel [read, write] |
whether text labels for toolbar buttons are enabled
If disabled (the default), the tool buttons will not use text labels. If enabled, text labels will be used.
Tool buttons and other widgets that wish to respond to this setting are responsible for reading the correct state on startup, and for connecting to the main window's widget's usesTextLabelChanged() signal.