|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.gui.QMainWindow
public class QMainWindow
The QMainWindow class provides a main application window.
QToolBar
s, QDockWidget
s, a QMenuBar
, and a QStatusBar
. The layout has a center area that can be occupied by any kind of widget. You can see an image of the layout below. QTextEdit
or a QGraphicsView
. Custom widgets can also be used for advanced applications. You set the central widget with setCentralWidget(). Main windows have either a single (SDI) or multiple (MDI) document interface. You create MDI applications in Qt by using a QMdiArea
as the central widget.
We will now examine each of the other widgets that can be added to a main window. We give examples on how to create and add them.Creating Menus
Qt implements menus in QMenu
and QMainWindow keeps them in a QMenuBar
. QAction
s are added to the menus, which display them as menu items.
You can add new menus to the main window's menu bar by calling menuBar(), which returns the QMenuBar
for the window, and then add a menu with QMenuBar::addMenu()
.
QMainWindow comes with a default menu bar, but you can also set one yourself with setMenuBar(). If you wish to implement a custom menu bar (i.e., not use the QMenuBar
widget), you can set it with setMenuWidget().
An example of how to create menus follows:
The following code example is written in c++.
void MainWindow::createMenus() { fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newAct); fileMenu->addAction(openAct); fileMenu->addAction(saveAct);The createPopupMenu() function creates popup menus when the main window receives context menu events. The default implementation generates a menu with the checkable actions from the dock widgets and toolbars. You can reimplement createPopupMenu() for a custom menu.
QToolBar
class. You add a toolbar to a main window with addToolBar(). You control the initial position of toolbars by assigning them to a specific Qt::ToolBarArea
. You can split an area by inserting a toolbar break - think of this as a line break in text editing - with addToolBarBreak() or insertToolBarBreak(). You can also restrict placement by the user with QToolBar::setAllowedAreas()
and QToolBar::setMovable()
.
The size of toolbar icons can be retrieved with iconSize(). The sizes are platform dependent; you can set a fixed size with setIconSize(). You can alter the appearance of all tool buttons in the toolbars with setToolButtonStyle().
An example of toolbar creation follows:
The following code example is written in c++.
void MainWindow::createToolBars() { fileToolBar = addToolBar(tr("File")); fileToolBar->addAction(newAct);
QDockWidget
class. A dock widget is a window that can be docked into the main window. You add dock widgets to a main window with addDockWidget(). There are four dock widget areas as given by the Qt::DockWidgetArea
enum: left, right, top, and bottom. You can specify which dock widget area that should occupy the corners where the areas overlap with setCorner(). By default each area can only contain one row (vertical or horizontal) of dock widgets, but if you enable nesting with setDockNestingEnabled(), dock widgets can be added in either direction.
Two dock widgets may also be stacked on top of each other. A QTabBar
is then used to select which of the widgets that should be displayed.
We give an example of how to create and add dock widgets to a main window:
QDockWidget dockWidget = new QDockWidget(tr("Dock Widget"), this); dockWidget.setAllowedAreas(Qt.DockWidgetArea.LeftDockWidgetArea); dockWidget.setWidget(dockWidgetContents); addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, dockWidget);
QStatusBar
for information on how to use it.QMenuBar
, QToolBar
, QStatusBar
, QDockWidget
, Application Example, Dock Widgets Example, MDI Example, SDI Example, and Menus Example.
Nested Class Summary | |
---|---|
static class |
QMainWindow.DockOption
This enum contains flags that specify the docking behavior of QMainWindow . |
static class |
QMainWindow.DockOptions
|
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget |
---|
QWidget.RenderFlag, QWidget.RenderFlags |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary | |
---|---|
QSignalEmitter.Signal1 |
iconSizeChanged
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
toolButtonStyleChanged
This signal takes 1 generic argument(s). |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QMainWindow()
Constructs a QMainWindow with the given parent and the specified widget flags. |
|
QMainWindow(QWidget parent)
Constructs a QMainWindow with the given parent and the specified widget flags. |
|
QMainWindow(QWidget parent,
Qt.WindowFlags flags)
Constructs a QMainWindow with the given parent and the specified widget flags. |
|
QMainWindow(QWidget parent,
Qt.WindowType[] flags)
|
Method Summary | |
---|---|
void |
addDockWidget(Qt.DockWidgetArea area,
QDockWidget dockwidget)
Adds the given dockwidget to the specified area. |
void |
addDockWidget(Qt.DockWidgetArea area,
QDockWidget dockwidget,
Qt.Orientation orientation)
Adds dockwidget into the given area in the direction specified by the orientation. |
void |
addToolBar(Qt.ToolBarArea area,
QToolBar toolbar)
Adds the toolbar into the specified area in this main window. |
void |
addToolBar(QToolBar toolbar)
Equivalent of calling addToolBar( Qt::TopToolBarArea , toolbar) |
QToolBar |
addToolBar(java.lang.String title)
Creates a QToolBar object, setting its window title to title, and inserts it into the top toolbar area. |
void |
addToolBarBreak()
Adds a toolbar break to the given area after all the other objects that are present. |
void |
addToolBarBreak(Qt.ToolBarArea area)
Adds a toolbar break to the given area after all the other objects that are present. |
QWidget |
centralWidget()
Returns the central widget for the main window. |
Qt.DockWidgetArea |
corner(Qt.Corner corner)
Returns the dock widget area that occupies the specified corner. |
QMenu |
createPopupMenu()
Returns a popup menu containing checkable entries for the toolbars and dock widgets present in the main window. |
QMainWindow.DockOptions |
dockOptions()
This property holds the docking behavior of QMainWindow. |
Qt.DockWidgetArea |
dockWidgetArea(QDockWidget dockwidget)
Returns the Qt::DockWidgetArea for dockwidget. |
QSize |
iconSize()
This property holds size of toolbar icons in this mainwindow. |
void |
insertToolBar(QToolBar before,
QToolBar toolbar)
Inserts the toolbar into the area occupied by the before toolbar so that it appears before it. |
void |
insertToolBarBreak(QToolBar before)
Inserts a toolbar break before the toolbar specified by before. |
boolean |
isAnimated()
This property holds whether manipulating dock widgets and tool bars is animated. |
boolean |
isDockNestingEnabled()
This property holds whether docks can be nested. |
QMenuBar |
menuBar()
Returns the menu bar for the main window. |
QWidget |
menuWidget()
Returns the menu bar for the main window. |
void |
removeDockWidget(QDockWidget dockwidget)
Removes the dockwidget from the main window layout and hides it. |
void |
removeToolBar(QToolBar toolbar)
Removes the toolbar from the main window layout and hides it. |
void |
removeToolBarBreak(QToolBar before)
Removes a toolbar break previously inserted before the toolbar specified by before. |
boolean |
restoreDockWidget(QDockWidget dockwidget)
Restores the state of dockwidget if it is created after the call to restoreState() . |
boolean |
restoreState(QByteArray state)
Restores the state of this mainwindow's toolbars and dockwidgets. |
boolean |
restoreState(QByteArray state,
int version)
Restores the state of this mainwindow's toolbars and dockwidgets. |
QByteArray |
saveState()
Saves the current state of this mainwindow's toolbars and dockwidgets. |
QByteArray |
saveState(int version)
Saves the current state of this mainwindow's toolbars and dockwidgets. |
void |
setAnimated(boolean enabled)
This property holds whether manipulating dock widgets and tool bars is animated. |
void |
setCentralWidget(QWidget widget)
Sets the given widget to be the main window's central widget. |
void |
setCorner(Qt.Corner corner,
Qt.DockWidgetArea area)
Sets the given dock widget area to occupy the specified corner. |
void |
setDockNestingEnabled(boolean enabled)
This property holds whether docks can be nested. |
void |
setDockOptions(QMainWindow.DockOption[] options)
|
void |
setDockOptions(QMainWindow.DockOptions options)
This property holds the docking behavior of QMainWindow. |
void |
setIconSize(QSize iconSize)
This property holds size of toolbar icons in this mainwindow. |
void |
setMenuBar(QMenuBar menubar)
Sets the menu bar for the main window to menuBar. |
void |
setMenuWidget(QWidget menubar)
Sets the menu bar for the main window to menuBar. |
void |
setStatusBar(QStatusBar statusbar)
Sets the status bar for the main window to statusbar. |
void |
setToolButtonStyle(Qt.ToolButtonStyle toolButtonStyle)
This property holds style of toolbar buttons in this mainwindow. |
void |
setUnifiedTitleAndToolBarOnMac(boolean set)
This property holds whether the window uses the unified title and toolbar look on Mac OS X. |
void |
splitDockWidget(QDockWidget after,
QDockWidget dockwidget,
Qt.Orientation orientation)
Splits the space covered by the first dock widget into two parts, moves the first dock widget into the first part, and moves the second dock widget into the second part. |
QStatusBar |
statusBar()
Returns the status bar for the main window. |
void |
tabifyDockWidget(QDockWidget first,
QDockWidget second)
Moves second dock widget on top of first dock widget, creating a tabbed docked area in the main window. |
Qt.ToolBarArea |
toolBarArea(QToolBar toolbar)
Returns the Qt::ToolBarArea for toolbar. |
boolean |
toolBarBreak(QToolBar toolbar)
Returns whether there is a toolbar break before the toolbar. |
Qt.ToolButtonStyle |
toolButtonStyle()
This property holds style of toolbar buttons in this mainwindow. |
boolean |
unifiedTitleAndToolBarOnMac()
This property holds whether the window uses the unified title and toolbar look on Mac OS X. |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal1 iconSizeChanged
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.core.QSize(named: iconSize)>:
This signal is emitted when the size of the icons used in the window is changed. The new icon size is passed in iconSize.
You can connect this signal to other components to help maintain a consistent appearance for your application.
setIconSize()
.
public final QSignalEmitter.Signal1 toolButtonStyleChanged
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.core.Qt$ToolButtonStyle(named: toolButtonStyle)>:
This signal is emitted when the style used for tool buttons in the window is changed. The new style is passed in toolButtonStyle.
You can connect this signal to other components to help maintain a consistent appearance for your application.
setToolButtonStyle()
.
Constructor Detail |
---|
public QMainWindow(QWidget parent, Qt.WindowType[] flags)
public QMainWindow(QWidget parent)
public QMainWindow()
public QMainWindow(QWidget parent, Qt.WindowFlags flags)
Method Detail |
---|
public final void addDockWidget(Qt.DockWidgetArea area, QDockWidget dockwidget)
public final void addDockWidget(Qt.DockWidgetArea area, QDockWidget dockwidget, Qt.Orientation orientation)
public final void addToolBar(QToolBar toolbar)
Qt::TopToolBarArea
, toolbar)
public final void addToolBar(Qt.ToolBarArea area, QToolBar toolbar)
insertToolBar()
, addToolBarBreak()
, and insertToolBarBreak()
.
public final QToolBar addToolBar(java.lang.String title)
QToolBar
object, setting its window title to title, and inserts it into the top toolbar area.
public final void addToolBarBreak()
public final void addToolBarBreak(Qt.ToolBarArea area)
public final QWidget centralWidget()
setCentralWidget()
.
public final Qt.DockWidgetArea corner(Qt.Corner corner)
setCorner()
.
public final QMainWindow.DockOptions dockOptions()
AnimatedDocks
| AllowTabbedDocks
.
public final Qt.DockWidgetArea dockWidgetArea(QDockWidget dockwidget)
Qt::DockWidgetArea
for dockwidget. If dockwidget has not been added to the main window, this function returns Qt::NoDockWidgetArea. addDockWidget()
, splitDockWidget()
, and Qt::DockWidgetArea
.
public final QSize iconSize()
public final void insertToolBar(QToolBar before, QToolBar toolbar)
insertToolBarBreak()
, addToolBar()
, and addToolBarBreak()
.
public final void insertToolBarBreak(QToolBar before)
public final boolean isAnimated()
By default, this property is set. It may be cleared if the main window contains widgets which are slow at resizing or repainting themselves.
Setting this property is identical to setting the AnimatedDocks
option using setDockOptions()
.
public final boolean isDockNestingEnabled()
Dock nesting is only necessary in applications that contain a lot of dock widgets. It gives the user greater freedom in organizing their main window. However, dock nesting leads to more complex (and less intuitive) behavior when a dock widget is dragged over the main window, since there are more ways in which a dropped dock widget may be placed in the dock area.
Setting this property is identical to setting the AllowNestedDocks
option using setDockOptions()
.
public final QMenuBar menuBar()
If you want all windows in a Mac application to share one menu bar, don't use this function to create it, because the menu bar created here will have this QMainWindow as its parent. Instead, you must create a menu bar that does not have a parent, which you can then share among all the Mac windows. Create a parent-less menu bar this way:
QMenuBar menuBar = new QMenuBar();
setMenuBar()
.
public final QWidget menuWidget()
setMenuWidget()
.
public final void removeDockWidget(QDockWidget dockwidget)
public final void removeToolBar(QToolBar toolbar)
public final void removeToolBarBreak(QToolBar before)
public final boolean restoreDockWidget(QDockWidget dockwidget)
restoreState()
. Returns true if the state was restored; otherwise returns false.
public final boolean restoreState(QByteArray state)
saveState()
.
public final boolean restoreState(QByteArray state, int version)
saveState()
.
public final QByteArray saveState()
The objectName
property is used to identify each QToolBar
and QDockWidget
. You should make sure that this property is unique for each QToolBar
and QDockWidget
you add to the QMainWindow
To restore the saved state, pass the return value and version number to restoreState()
.
restoreState()
.
public final QByteArray saveState(int version)
The objectName
property is used to identify each QToolBar
and QDockWidget
. You should make sure that this property is unique for each QToolBar
and QDockWidget
you add to the QMainWindow
To restore the saved state, pass the return value and version number to restoreState()
.
restoreState()
.
public final void setAnimated(boolean enabled)
By default, this property is set. It may be cleared if the main window contains widgets which are slow at resizing or repainting themselves.
Setting this property is identical to setting the AnimatedDocks
option using setDockOptions()
.
public final void setCentralWidget(QWidget widget)
Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.
centralWidget()
.
public final void setCorner(Qt.Corner corner, Qt.DockWidgetArea area)
corner()
.
public final void setDockNestingEnabled(boolean enabled)
Dock nesting is only necessary in applications that contain a lot of dock widgets. It gives the user greater freedom in organizing their main window. However, dock nesting leads to more complex (and less intuitive) behavior when a dock widget is dragged over the main window, since there are more ways in which a dropped dock widget may be placed in the dock area.
Setting this property is identical to setting the AllowNestedDocks
option using setDockOptions()
.
public final void setDockOptions(QMainWindow.DockOption[] options)
public final void setDockOptions(QMainWindow.DockOptions options)
AnimatedDocks
| AllowTabbedDocks
.
public final void setIconSize(QSize iconSize)
public final void setMenuBar(QMenuBar menubar)
Note: QMainWindow takes ownership of the menuBar pointer and deletes it at the appropriate time.
menuBar()
.
public final void setMenuWidget(QWidget menubar)
QMainWindow takes ownership of the menuBar pointer and deletes it at the appropriate time.
menuWidget()
.
public final void setStatusBar(QStatusBar statusbar)
Setting the status bar to 0 will remove it from the main window. Note that QMainWindow takes ownership of the statusbar pointer and deletes it at the appropriate time.
statusBar()
.
public final void setToolButtonStyle(Qt.ToolButtonStyle toolButtonStyle)
Qt::ToolButtonIconOnly
.
public final void setUnifiedTitleAndToolBarOnMac(boolean set)
If set to true, then the top toolbar area is replaced with a Carbon HIToolbar and all toolbars in the top toolbar area are moved to that. Any toolbars added afterwards will also be added to the Carbon HIToolbar. This means a couple of things.
showFullScreen()
on the main window, the QToolbar will disappear since it is considered to be part of the title bar. You can work around this by turning off the unified toolbar before you call showFullScreen()
and restoring it after you call showNormal()
.The Qt::WA_MacBrushedMetal
attribute takes precedence over this property.
public final void splitDockWidget(QDockWidget after, QDockWidget dockwidget, Qt.Orientation orientation)
The orientation specifies how the space is divided: A Qt::Horizontal
split places the second dock widget to the right of the first; a Qt::Vertical
split places the second dock widget below the first.
Note: if first is currently in a tabbed docked area, second will be added as a new tab, not as a neighbor of first. This is because a single tab can contain only one dock widget.
Note: The Qt::LayoutDirection
influences the order of the dock widgets in the two parts of the divided area. When right-to-left layout direction is enabled, the placing of the dock widgets will be reversed.
tabifyDockWidget()
, addDockWidget()
, and removeDockWidget()
.
public final QStatusBar statusBar()
setStatusBar()
.
public final void tabifyDockWidget(QDockWidget first, QDockWidget second)
public final Qt.ToolBarArea toolBarArea(QToolBar toolbar)
Qt::ToolBarArea
for toolbar. If toolbar has not been added to the main window, this function returns Qt::NoToolBarArea. addToolBar()
, addToolBarBreak()
, and Qt::ToolBarArea
.
public final boolean toolBarBreak(QToolBar toolbar)
addToolBarBreak()
, and insertToolBarBreak()
.
public final Qt.ToolButtonStyle toolButtonStyle()
Qt::ToolButtonIconOnly
.
public final boolean unifiedTitleAndToolBarOnMac()
If set to true, then the top toolbar area is replaced with a Carbon HIToolbar and all toolbars in the top toolbar area are moved to that. Any toolbars added afterwards will also be added to the Carbon HIToolbar. This means a couple of things.
showFullScreen()
on the main window, the QToolbar will disappear since it is considered to be part of the title bar. You can work around this by turning off the unified toolbar before you call showFullScreen()
and restoring it after you call showNormal()
.The Qt::WA_MacBrushedMetal
attribute takes precedence over this property.
public QMenu createPopupMenu()
By default, this function is called by the main window when the user activates a context menu, typically by right-clicking on a toolbar or a dock widget.
If you want to create a custom popup menu, reimplement this function and return a newly-created popup menu. Ownership of the popup menu is transferred to the caller.
addDockWidget()
, addToolBar()
, and menuBar()
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |