Table Of Contents

Previous topic

QFocusFrame

Next topic

QDialogButtonBox

QDockWidget

Synopsis

Functions

Signals

Detailed Description

The PySide.QtGui.QDockWidget class provides a widget that can be docked inside a PySide.QtGui.QMainWindow or floated as a top-level window on the desktop.

PySide.QtGui.QDockWidget provides the concept of dock widgets, also know as tool palettes or utility windows. Dock windows are secondary windows placed in the dock widget area around the central widget in a PySide.QtGui.QMainWindow .

../../_images/mainwindow-docks.png

Dock windows can be moved inside their current area, moved into new areas and floated (e.g., undocked) by the end-user. The PySide.QtGui.QDockWidget API allows the programmer to restrict the dock widgets ability to move, float and close, as well as the areas in which they can be placed.

Appearance

A PySide.QtGui.QDockWidget consists of a title bar and the content area. The title bar displays the dock widgets window title , a float button and a close button. Depending on the state of the PySide.QtGui.QDockWidget , the float and close buttons may be either disabled or not shown at all.

The visual appearance of the title bar and buttons is dependent on the style in use.

A PySide.QtGui.QDockWidget acts as a wrapper for its child widget, set with PySide.QtGui.QDockWidget.setWidget() . Custom size hints, minimum and maximum sizes and size policies should be implemented in the child widget. PySide.QtGui.QDockWidget will respect them, adjusting its own constraints to include the frame and title. Size constraints should not be set on the PySide.QtGui.QDockWidget itself, because they change depending on whether it is docked; a docked PySide.QtGui.QDockWidget has no frame and a smaller title bar.

See also

PySide.QtGui.QMainWindow Dock Widgets Example

class PySide.QtGui.QDockWidget([parent=None[, flags=0]])
class PySide.QtGui.QDockWidget(title[, parent=None[, flags=0]])
Parameters:
PySide.QtGui.QDockWidget.DockWidgetFeature
Constant Description
QDockWidget.DockWidgetClosable The dock widget can be closed. On some systems the dock widget always has a close button when it’s floating (for example on MacOS 10.5).
QDockWidget.DockWidgetMovable The dock widget can be moved between docks by the user.
QDockWidget.DockWidgetFloatable The dock widget can be detached from the main window, and floated as an independent window.
QDockWidget.DockWidgetVerticalTitleBar The dock widget displays a vertical title bar on its left side. This can be used to increase the amount of vertical space in a PySide.QtGui.QMainWindow .
QDockWidget.AllDockWidgetFeatures (Deprecated) The dock widget can be closed, moved, and floated. Since new features might be added in future releases, the look and behavior of dock widgets might change if you use this flag. Please specify individual flags instead.
QDockWidget.NoDockWidgetFeatures The dock widget cannot be closed, moved, or floated.
PySide.QtGui.QDockWidget.allowedAreas()
Return type:PySide.QtCore.Qt.DockWidgetAreas
PySide.QtGui.QDockWidget.allowedAreasChanged(allowedAreas)
Parameters:allowedAreasPySide.QtCore.Qt.DockWidgetAreas
PySide.QtGui.QDockWidget.dockLocationChanged(area)
Parameters:areaPySide.QtCore.Qt.DockWidgetArea
PySide.QtGui.QDockWidget.features()
Return type:PySide.QtGui.QDockWidget.DockWidgetFeatures

This property holds whether the dock widget is movable, closable, and floatable.

By default, this property is set to a combination of DockWidgetClosable , DockWidgetMovable and DockWidgetFloatable .

See also

QDockWidget.DockWidgetFeature

PySide.QtGui.QDockWidget.featuresChanged(features)
Parameters:featuresPySide.QtGui.QDockWidget.DockWidgetFeatures
PySide.QtGui.QDockWidget.initStyleOption(option)
Parameters:optionPySide.QtGui.QStyleOptionDockWidget

Initialize option with the values from this PySide.QtGui.QDockWidget . This method is useful for subclasses when they need a PySide.QtGui.QStyleOptionDockWidget , but don’t want to fill in all the information themselves.

PySide.QtGui.QDockWidget.isAreaAllowed(area)
Parameters:areaPySide.QtCore.Qt.DockWidgetArea
Return type:PySide.QtCore.bool
PySide.QtGui.QDockWidget.isFloating()
Return type:PySide.QtCore.bool

This property holds whether the dock widget is floating.

A floating dock widget is presented to the user as an independent window “on top” of its parent PySide.QtGui.QMainWindow , instead of being docked in the PySide.QtGui.QMainWindow .

By default, this property is true.

PySide.QtGui.QDockWidget.setAllowedAreas(areas)
Parameters:areasPySide.QtCore.Qt.DockWidgetAreas
PySide.QtGui.QDockWidget.setFeatures(features)
Parameters:featuresPySide.QtGui.QDockWidget.DockWidgetFeatures

This property holds whether the dock widget is movable, closable, and floatable.

By default, this property is set to a combination of DockWidgetClosable , DockWidgetMovable and DockWidgetFloatable .

See also

QDockWidget.DockWidgetFeature

PySide.QtGui.QDockWidget.setFloating(floating)
Parameters:floatingPySide.QtCore.bool

This property holds whether the dock widget is floating.

A floating dock widget is presented to the user as an independent window “on top” of its parent PySide.QtGui.QMainWindow , instead of being docked in the PySide.QtGui.QMainWindow .

By default, this property is true.

PySide.QtGui.QDockWidget.setTitleBarWidget(widget)
Parameters:widgetPySide.QtGui.QWidget

Sets an arbitrary widget as the dock widget’s title bar. If widget is 0, any custom title bar widget previously set on the dock widget is removed, but not deleted, and the default title bar will be used instead.

If a title bar widget is set, PySide.QtGui.QDockWidget will not use native window decorations when it is floated.

Here are some tips for implementing custom title bars:

  • Mouse events that are not explicitly handled by the title bar widget must be ignored by calling QMouseEvent.ignore() . These events then propagate to the PySide.QtGui.QDockWidget parent, which handles them in the usual manner, moving when the title bar is dragged, docking and undocking when it is double-clicked, etc.

  • When DockWidgetVerticalTitleBar is set on PySide.QtGui.QDockWidget , the title bar widget is repositioned accordingly. In PySide.QtGui.QWidget.resizeEvent() , the title bar should check what orientation it should assume:

    dockWidget = parentWidget()
    if dockWidget.features() & QDockWidget.DockWidgetVerticalTitleBar:
        # I need to be vertical
    else:
        # I need to be horizontal
  • The title bar widget must have a valid QWidget.sizeHint() and QWidget.minimumSizeHint() . These functions should take into account the current orientation of the title bar.

  • It is not possible to remove a title bar from a dock widget. However, a similar effect can be achieved by setting a default constructed PySide.QtGui.QWidget as the title bar widget.

Using qobject_cast() as shown above, the title bar widget has full access to its parent PySide.QtGui.QDockWidget . Hence it can perform such operations as docking and hiding in response to user actions.

See also

PySide.QtGui.QDockWidget.titleBarWidget() DockWidgetVerticalTitleBar

PySide.QtGui.QDockWidget.setWidget(widget)
Parameters:widgetPySide.QtGui.QWidget

Sets the widget for the dock widget to widget .

If the dock widget is visible when widget is added, you must PySide.QtGui.QWidget.show() it explicitly.

Note that you must add the layout of the widget before you call this function; if not, the widget will not be visible.

PySide.QtGui.QDockWidget.titleBarWidget()
Return type:PySide.QtGui.QWidget

Returns the custom title bar widget set on the PySide.QtGui.QDockWidget , or 0 if no custom title bar has been set.

PySide.QtGui.QDockWidget.toggleViewAction()
Return type:PySide.QtGui.QAction

Returns a checkable action that can be used to show or close this dock widget.

The action’s text is set to the dock widget’s window title.

PySide.QtGui.QDockWidget.topLevelChanged(topLevel)
Parameters:topLevelPySide.QtCore.bool
PySide.QtGui.QDockWidget.visibilityChanged(visible)
Parameters:visiblePySide.QtCore.bool
PySide.QtGui.QDockWidget.widget()
Return type:PySide.QtGui.QWidget

Returns the widget for the dock widget. This function returns zero if the widget has not been set.