Q3DockWindow Class

The Q3DockWindow class provides a widget which can be docked inside a Q3DockArea or floated as a top level window on the desktop. 更多...

头: #include <Q3DockWindow>
继承: Q3Frame
继承者: Q3ToolBar

公共类型

enum CloseMode { Never, Docked, Undocked, Always }
enum Place { InDock, OutsideDock }

特性

公共函数

Q3DockWindow (Place p = InDock, QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0)
Q3DockWindow (QWidget * parent , const char * name = 0, Qt::WindowFlags f = 0)
~Q3DockWindow ()
Q3DockArea * area () const
QBoxLayout * boxLayout ()
int closeMode () const
QSize fixedExtent () const
bool isCloseEnabled () const
bool isHorizontalStretchable () const
bool isHorizontallyStretchable () const
bool isMovingEnabled () const
bool isResizeEnabled () const
bool isStretchable () const
bool isVerticalStretchable () const
bool isVerticallyStretchable () const
bool newLine () const
int offset () const
bool opaqueMoving () const
Qt::Orientation orientation () const
Place place () const
virtual void setCloseMode (int m )
virtual void setFixedExtentHeight (int h )
virtual void setFixedExtentWidth (int w )
void setHorizontalStretchable (bool b )
virtual void setHorizontallyStretchable (bool b )
virtual void setMovingEnabled (bool b )
virtual void setNewLine (bool b )
virtual void setOffset (int o )
virtual void setOpaqueMoving (bool b )
virtual void setResizeEnabled (bool b )
void setVerticalStretchable (bool b )
virtual void setVerticallyStretchable (bool b )
virtual void setWidget (QWidget * w )
QWidget * widget () const
QString windowTitle () const

重实现公共函数

virtual bool eventFilter (QObject * o , QEvent * e )
virtual QSize minimumSizeHint () const
virtual QSize sizeHint () const

公共槽

virtual void dock ()
virtual void setOrientation (Qt::Orientation o )
virtual void undock (QWidget * widget )
virtual void undock ()

信号

void orientationChanged (Qt::Orientation o )
void placeChanged (Q3DockWindow::Place p )
void visibilityChanged (bool visible )

重实现保护函数

virtual void contextMenuEvent (QContextMenuEvent * e )
virtual void drawContents (QPainter * p )
virtual void drawFrame (QPainter * p )
virtual bool event (QEvent * e )
virtual void hideEvent (QHideEvent * e )
virtual void resizeEvent (QResizeEvent * e )
virtual void showEvent (QShowEvent * e )

额外继承成员

详细描述

The Q3DockWindow class provides a widget which can be docked inside a Q3DockArea or floated as a top level window on the desktop.

This class handles moving, resizing, docking and undocking dock windows. Q3ToolBar 是子类化的 Q3DockWindow so the functionality provided for dock windows is available with the same API for toolbars.

Q3DockWindows in a Q3DockArea

Two Q3DockWindows ( Q3ToolBar s) in a Q3DockArea

A Q3DockWindow

A Floating Q3DockWindow

If the user drags the dock window into the dock area the dock window will be docked. If the user drags the dock area outside any dock areas the dock window will be undocked (floated) and will become a top level window. Double clicking a floating dock window's title bar will dock the dock window to the last dock area it was docked in. Double clicking a docked dock window's handle will undock (float) the dock window. If the user clicks the close button (which appears on floating dock windows by default) the dock window will disappear. You can control whether or not a dock window has a close button with setCloseMode ().

Q3MainWindow provides four dock areas (top, left, right and bottom) which can be used by dock windows. For many applications using the dock areas provided by Q3MainWindow is sufficient. (See the Q3DockArea documentation if you want to create your own dock areas.) In Q3MainWindow a right-click popup menu (the dock window menu) is available which lists dock windows and can be used to show or hide them. (The popup menu only lists dock windows that have a caption )。

When you construct a dock window you must pass it a Q3DockArea Q3MainWindow as its parent if you want it docked. Pass 0 for the parent if you want it floated.

Q3ToolBar *fileTools = new Q3ToolBar(this, "File Actions");
moveDockWindow(fileTools, Left);
					

In the example above we create a new Q3ToolBar in the constructor of a Q3MainWindow subclass (so that the this pointer points to the Q3MainWindow ). By default the toolbar will be added to the Top dock area, but we've moved it to the Left dock area.

A dock window is often used to contain a single widget. In these cases the widget can be set by calling setWidget (). If you're constructing a dock window that contains multiple widgets, e.g. a toolbar, arrange the widgets within a box layout inside the dock window. To do this use the boxLayout () function to get a pointer to the dock window's box layout, then add widgets to the layout using the box layout's QBoxLayout::addWidget () function. The dock window will dynamically set the orientation of the layout to be vertical or horizontal as necessary, although you can control this yourself with setOrientation ().

Although a common use of dock windows is for toolbars, they can be used with any widgets. When using larger widgets it may make sense for the dock window to be resizable by calling setResizeEnabled (). Resizable dock windows are given splitter-like handles to allow the user to resize them within their dock area. When resizable dock windows are undocked they become top level windows and can be resized like any other top level windows, e.g. by dragging a corner or edge.

Qt::Dock windows can be docked and undocked using dock () 和 undock (). A dock window's orientation can be set with setOrientation (). You can also use Q3DockArea::moveDockWindow (). If you're using a Q3MainWindow , Q3MainWindow::moveDockWindow () 和 Q3MainWindow::removeDockWindow () are available.

A dock window can have some preferred settings, for example, you can set a preferred offset from the left edge (or top edge for vertical dock areas) of the dock area using setOffset (). If you'd prefer a dock window to start on a new line when it is docked use setNewLine ()。 setFixedExtentWidth () 和 setFixedExtentHeight () functions can be used to define the dock window's preferred size, and the setHorizontallyStretchable () 和 setVerticallyStretchable () functions set whether the dock window can be stretched or not. Dock windows can be moved by default, but this can be changed with setMovingEnabled (). When a dock window is moved it is shown as a rectangular outline, but it can be shown normally using setOpaqueMoving ().

When a dock window's visibility changes, i.e. it is shown or hidden, the visibilityChanged () signal is emitted. When a dock window is docked, undocked or moved inside the dock area the placeChanged () 信号发射。

成员类型文档编制

enum Q3DockWindow:: CloseMode

This enum type specifies when (if ever) a dock window has a close button.

常量 描述
Q3DockWindow::Never 0 The dock window never has a close button and cannot be closed by the user.
Q3DockWindow::Docked 1 The dock window has a close button only when docked.
Q3DockWindow::Undocked 2 The dock window has a close button only when floating.
Q3DockWindow::Always Docked | Undocked The dock window always has a close button.

enum Q3DockWindow:: Place

This enum specifies the possible locations for a Q3DockWindow :

常量 描述
Q3DockWindow::InDock 0 Inside a Q3DockArea .
Q3DockWindow::OutsideDock 1 Floating as a top level window on the desktop.

特性文档编制

closeMode : int

This property holds the close mode of a dock window.

Defines when (if ever) the dock window has a close button. The choices are Never , Docked (i.e. only when docked), Undocked (only when undocked, i.e. floated) or Always .

默认为 Never .

访问函数:

int closeMode () const
virtual void setCloseMode (int m )

horizontallyStretchable : bool

This property holds whether the dock window is horizontally stretchable.

A dock window is horizontally stretchable if you call setHorizontallyStretchable(true) or setResizeEnabled (true)。

警告: Stretchability is broken. You must call setResizeEnabled (true) to get proper behavior and even then Q3DockWindow does not limit stretchablilty.

访问函数:

bool isHorizontallyStretchable () const
virtual void setHorizontallyStretchable (bool b )

另请参阅 setResizeEnabled ().

movingEnabled : bool

This property holds whether the user can move the dock window within the dock area, move the dock window to another dock area, or float the dock window.

This property is true by default.

访问函数:

bool isMovingEnabled () const
virtual void setMovingEnabled (bool b )

newLine : bool

This property holds whether the dock window prefers to start a new line in the dock area.

The default is false, i.e. the dock window doesn't require a new line in the dock area.

访问函数:

bool newLine () const
virtual void setNewLine (bool b )

offset : int

This property holds the dock window's preferred offset from the dock area's left edge (top edge for vertical dock areas).

默认为 0。

访问函数:

int offset () const
virtual void setOffset (int o )

opaqueMoving : bool

This property holds whether the dock window will be shown normally whilst it is being moved.

If this property is false, (the default), the dock window will be represented by an outline rectangle whilst it is being moved.

警告: Currently opaque moving has some problems and we do not recommend using it at this time. We expect to fix these problems in a future release.

访问函数:

bool opaqueMoving () const
virtual void setOpaqueMoving (bool b )

place : const Place

This property holds the location where the dock window is placed.

This is either InDock or OutsideDock .

访问函数:

Place place () const

另请参阅 Q3DockArea::moveDockWindow (), Q3DockArea::removeDockWindow (), Q3MainWindow::moveDockWindow (),和 Q3MainWindow::removeDockWindow ().

resizeEnabled : bool

This property holds whether the dock window is resizeable.

A resizeable dock window can be resized using splitter-like handles inside a dock area and like every other top level window when floating.

A dock window is both horizontally and vertically stretchable if you call setResizeEnabled(true).

This property is false by default.

访问函数:

bool isResizeEnabled () const
virtual void setResizeEnabled (bool b )

另请参阅 setVerticallyStretchable () 和 setHorizontallyStretchable ().

stretchable : const bool

This property holds whether the dock window is stretchable in the current orientation().

This property can be set using setHorizontallyStretchable () 和 setVerticallyStretchable (), or with setResizeEnabled ().

警告: Stretchability is broken. You must call setResizeEnabled (true) to get proper behavior and even then Q3DockWindow does not limit stretchablilty.

访问函数:

bool isStretchable () const

另请参阅 setResizeEnabled ().

verticallyStretchable : bool

This property holds whether the dock window is vertically stretchable.

A dock window is vertically stretchable if you call setVerticallyStretchable(true) or setResizeEnabled (true)。

警告: Stretchability is broken. You must call setResizeEnabled (true) to get proper behavior and even then Q3DockWindow does not limit stretchablilty.

访问函数:

bool isVerticallyStretchable () const
virtual void setVerticallyStretchable (bool b )

另请参阅 setResizeEnabled ().

成员函数文档编制

Q3DockWindow:: Q3DockWindow ( Place p = InDock, QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0)

构造 Q3DockWindow 采用父级 parent , called name and with widget flags f .

p is InDock , the dock window is docked into a dock area and parent must be a Q3DockArea Q3MainWindow 。若 parent Q3MainWindow the dock window will be docked in the main window's Top dock area.

p is OutsideDock , the dock window is created as a floating window.

We recommend creating the dock area InDock 采用 Q3MainWindow as parent then calling Q3MainWindow::moveDockWindow () to move the dock window where you want it.

Q3DockWindow:: Q3DockWindow ( QWidget * parent , const char * name = 0, Qt::WindowFlags f = 0)

构造 Q3DockWindow 采用父级 parent , called name and with widget flags f .

Q3DockWindow:: ~Q3DockWindow ()

Destroys the dock window and its child widgets.

Q3DockArea * Q3DockWindow:: area () const

Returns the dock area in which this dock window is docked, or 0 if the dock window is floating.

QBoxLayout * Q3DockWindow:: boxLayout ()

Returns the layout which is used for adding widgets to the dock window. The layout's orientation is set automatically to match the orientation of the dock window. You can add widgets to the layout using the box layout's QBoxLayout::addWidget () 函数。

If the dock window only needs to contain a single widget use setWidget () 代替。

另请参阅 setWidget () 和 setOrientation ().

[virtual protected] void Q3DockWindow:: contextMenuEvent ( QContextMenuEvent * e )

重实现自 QWidget::contextMenuEvent ().

[virtual slot] void Q3DockWindow:: dock ()

Docks the dock window into the last dock area in which it was docked.

If the dock window has no last dock area (e.g. it was created as a floating window and has never been docked), or if the last dock area it was docked in does not exist (e.g. the dock area has been deleted), nothing happens.

The dock window will dock with the dock area regardless of the return value of Q3DockArea::isDockWindowAccepted ().

另请参阅 undock (), Q3DockArea::moveDockWindow (), Q3DockArea::removeDockWindow (), Q3MainWindow::moveDockWindow (), Q3MainWindow::removeDockWindow (),和 Q3DockArea::isDockWindowAccepted ().

[virtual protected] void Q3DockWindow:: drawContents ( QPainter * p )

重实现自 Q3Frame::drawContents ().

[virtual protected] void Q3DockWindow:: drawFrame ( QPainter * p )

重实现自 Q3Frame::drawFrame ().

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

重实现自 QObject::event ().

[虚拟] bool Q3DockWindow:: eventFilter ( QObject * o , QEvent * e )

重实现自 QObject::eventFilter ().

QSize Q3DockWindow:: fixedExtent () const

Returns the dock window's preferred size (fixed extent).

另请参阅 setFixedExtentWidth () 和 setFixedExtentHeight ().

[virtual protected] void Q3DockWindow:: hideEvent ( QHideEvent * e )

重实现自 QWidget::hideEvent ().

bool Q3DockWindow:: isCloseEnabled () const

Returns true if the dock window has a close button; otherwise returns false. The result depends on the dock window's Place 及其 CloseMode .

另请参阅 setCloseMode ().

bool Q3DockWindow:: isHorizontalStretchable () const

Returns true if the dock window can be stretched horizontally; otherwise returns false.

bool Q3DockWindow:: isVerticalStretchable () const

Returns true if the dock window can be stretched vertically; otherwise returns false.

[虚拟] QSize Q3DockWindow:: minimumSizeHint () const

重实现自 QWidget::minimumSizeHint ().

Qt::Orientation Q3DockWindow:: orientation () const

Returns the orientation of the dock window.

另请参阅 setOrientation () 和 orientationChanged ().

[signal] void Q3DockWindow:: orientationChanged ( Qt::Orientation o )

This signal is emitted when the orientation of the dock window is changed. The new orientation is o .

[signal] void Q3DockWindow:: placeChanged ( Q3DockWindow::Place p )

This signal is emitted when the dock window is docked ( p is InDock ), undocked ( p is OutsideDock ) or moved inside the the dock area.

另请参阅 Q3DockArea::moveDockWindow (), Q3DockArea::removeDockWindow (), Q3MainWindow::moveDockWindow (),和 Q3MainWindow::removeDockWindow ().

[virtual protected] void Q3DockWindow:: resizeEvent ( QResizeEvent * e )

重实现自 QWidget::resizeEvent ().

[虚拟] void Q3DockWindow:: setFixedExtentHeight ( int h )

Sets the dock window's preferred height for its fixed extent (size) to h .

另请参阅 setFixedExtentWidth ().

[虚拟] void Q3DockWindow:: setFixedExtentWidth ( int w )

Sets the dock window's preferred width for its fixed extent (size) to w .

另请参阅 setFixedExtentHeight ().

void Q3DockWindow:: setHorizontalStretchable ( bool b )

b is true the dock window is set to be horizontally stretchable.

另请参阅 isHorizontalStretchable ().

[virtual slot] void Q3DockWindow:: setOrientation ( Qt::Orientation o )

Sets the orientation of the dock window to o . The orientation is propagated to the layout boxLayout ().

警告: All undocked Q3ToolBars will always have a horizontal orientation.

另请参阅 orientation ().

void Q3DockWindow:: setVerticalStretchable ( bool b )

b is true the dock window is set to be vertically stretchable.

另请参阅 isVerticalStretchable ().

[虚拟] void Q3DockWindow:: setWidget ( QWidget * w )

Sets the dock window's main widget to w .

另请参阅 widget () 和 boxLayout ().

[virtual protected] void Q3DockWindow:: showEvent ( QShowEvent * e )

重实现自 QWidget::showEvent ().

[虚拟] QSize Q3DockWindow:: sizeHint () const

重实现自 QWidget::sizeHint ().

[virtual slot] void Q3DockWindow:: undock ( QWidget * widget )

Undocks the specified widget from its current dock area if it is docked; otherwise does nothing.

另请参阅 dock (), Q3DockArea::moveDockWindow (), Q3DockArea::removeDockWindow (), Q3MainWindow::moveDockWindow (),和 Q3MainWindow::removeDockWindow ().

[virtual slot] void Q3DockWindow:: undock ()

Undocks the Q3DockWindow from its current dock area if it is docked; otherwise does nothing.

另请参阅 dock (), Q3DockArea::moveDockWindow (), Q3DockArea::removeDockWindow (), Q3MainWindow::moveDockWindow (),和 Q3MainWindow::removeDockWindow ().

[signal] void Q3DockWindow:: visibilityChanged ( bool visible )

This signal is emitted when the visibility of the dock window relatively to its dock area is changed. If visible is true, the Q3DockWindow is now visible to the dock area, otherwise it has been hidden.

A dock window can be hidden if it has a close button which the user has clicked. In the case of a Q3MainWindow a dock window can have its visibility changed (hidden or shown) by clicking its name in the dock window menu that lists the Q3MainWindow 's dock windows.

QWidget * Q3DockWindow:: widget () const

Returns the dock window's main widget.

另请参阅 setWidget ().

QString Q3DockWindow:: windowTitle () const

Returns the dock window's title.