QDockWidget露
The
QDockWidgetclass provides a widget that can be docked inside aQMainWindowor floated as a top-level window on the desktop. More鈥

Synopsis露
Functions露
def
allowedAreas()def
features()def
initStyleOption(option)def
isAreaAllowed(area)def
isFloating()def
setAllowedAreas(areas)def
setFeatures(features)def
setFloating(floating)def
setTitleBarWidget(widget)def
setWidget(widget)def
titleBarWidget()def
toggleViewAction()def
widget()
Signals露
def
allowedAreasChanged(allowedAreas)def
dockLocationChanged(area)def
featuresChanged(features)def
topLevelChanged(topLevel)def
visibilityChanged(visible)
Detailed Description露
QDockWidgetprovides 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 thecentral widgetin aQMainWindow.![]()
Dock windows can be moved inside their current area, moved into new areas and floated (e.g., undocked) by the end-user. The
QDockWidgetAPI 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
QDockWidgetconsists of a title bar and the content area. The title bar displays the dock widgetswindow title, a float button and a close button. Depending on the state of theQDockWidget, 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
stylein use.A
QDockWidgetacts as a wrapper for its child widget, set withsetWidget(). Custom size hints, minimum and maximum sizes and size policies should be implemented in the child widget.QDockWidgetwill respect them, adjusting its own constraints to include the frame and title. Size constraints should not be set on theQDockWidgetitself, because they change depending on whether it is docked; a dockedQDockWidgethas no frame and a smaller title bar.Note
On macOS, if the
QDockWidgethas a native window handle (for example, ifwinId()is called on it or the child widget), then due to a limitation it will not be possible to drag the dock widget when undocking. Starting the drag will undock the dock widget, but a second drag will be needed to move the dock widget itself.See also
- class PySide2.QtWidgets.QDockWidget([parent=None[, flags=Qt.WindowFlags()]])露
PySide2.QtWidgets.QDockWidget(title[, parent=None[, flags=Qt.WindowFlags()]])
- param parent:
- param title:
str
- param flags:
WindowFlags
Constructs a
QDockWidgetwith parentparentand window flagsflags. The dock widget will be placed in the left dock widget area.Constructs a
QDockWidgetwith parentparentand window flagsflags. The dock widget will be placed in the left dock widget area.The window title is set to
title. This title is used when theQDockWidgetis docked and undocked. It is also used in the context menu provided byQMainWindow.See also
- PySide2.QtWidgets.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鈥檚 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
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.
- PySide2.QtWidgets.QDockWidget.allowedAreas()露
- Return type:
DockWidgetAreas
This property holds areas where the dock widget may be placed.
The default is
AllDockWidgetAreas.See also
DockWidgetArea
- PySide2.QtWidgets.QDockWidget.allowedAreasChanged(allowedAreas)露
- Parameters:
allowedAreas 鈥
DockWidgetAreas
- PySide2.QtWidgets.QDockWidget.dockLocationChanged(area)露
- Parameters:
area 鈥
DockWidgetArea
- PySide2.QtWidgets.QDockWidget.features()露
- Return type:
DockWidgetFeatures
This property holds whether the dock widget is movable, closable, and floatable.
By default, this property is set to a combination of
DockWidgetClosable,DockWidgetMovableandDockWidgetFloatable.See also
DockWidgetFeature
- PySide2.QtWidgets.QDockWidget.featuresChanged(features)露
- Parameters:
features 鈥
DockWidgetFeatures
- PySide2.QtWidgets.QDockWidget.initStyleOption(option)露
- Parameters:
Initialize
optionwith the values from thisQDockWidget. This method is useful for subclasses when they need aQStyleOptionDockWidget, but don鈥檛 want to fill in all the information themselves.See also
- PySide2.QtWidgets.QDockWidget.isAreaAllowed(area)露
- Parameters:
area 鈥
DockWidgetArea- Return type:
bool
Returns
trueif this dock widget can be placed in the givenarea; otherwise returnsfalse.
- PySide2.QtWidgets.QDockWidget.isFloating()露
- Return type:
bool
This property holds whether the dock widget is floating.
A floating dock widget is presented to the user as an independent window 鈥渙n top鈥 of its parent
QMainWindow, instead of being docked in theQMainWindow.By default, this property is
true.When this property changes, the
topLevelChanged()signal is emitted.See also
- PySide2.QtWidgets.QDockWidget.setAllowedAreas(areas)露
- Parameters:
areas 鈥
DockWidgetAreas
This property holds areas where the dock widget may be placed.
The default is
AllDockWidgetAreas.See also
DockWidgetArea
- PySide2.QtWidgets.QDockWidget.setFeatures(features)露
- Parameters:
features 鈥
DockWidgetFeatures
This property holds whether the dock widget is movable, closable, and floatable.
By default, this property is set to a combination of
DockWidgetClosable,DockWidgetMovableandDockWidgetFloatable.See also
DockWidgetFeature
- PySide2.QtWidgets.QDockWidget.setFloating(floating)露
- Parameters:
floating 鈥 bool
This property holds whether the dock widget is floating.
A floating dock widget is presented to the user as an independent window 鈥渙n top鈥 of its parent
QMainWindow, instead of being docked in theQMainWindow.By default, this property is
true.When this property changes, the
topLevelChanged()signal is emitted.See also
- PySide2.QtWidgets.QDockWidget.setTitleBarWidget(widget)露
- Parameters:
widget 鈥
PySide2.QtWidgets.QWidget
Sets an arbitrary
widgetas the dock widget鈥檚 title bar. IfwidgetisNone, 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,
QDockWidgetwill 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
ignore(). These events then propagate to theQDockWidgetparent, which handles them in the usual manner, moving when the title bar is dragged, docking and undocking when it is double-clicked, etc.When
DockWidgetVerticalTitleBaris set onQDockWidget, the title bar widget is repositioned accordingly. InresizeEvent(), 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
sizeHint()andminimumSizeHint(). 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
QWidgetas the title bar widget.
Using
qobject_cast()as shown above, the title bar widget has full access to its parentQDockWidget. Hence it can perform such operations as docking and hiding in response to user actions.See also
titleBarWidget()DockWidgetVerticalTitleBar
- PySide2.QtWidgets.QDockWidget.setWidget(widget)露
- Parameters:
widget 鈥
PySide2.QtWidgets.QWidget
Sets the widget for the dock widget to
widget.If the dock widget is visible when
widgetis added, you mustshow()it explicitly.Note that you must add the layout of the
widgetbefore you call this function; if not, thewidgetwill not be visible.See also
- PySide2.QtWidgets.QDockWidget.titleBarWidget()露
- Return type:
Returns the custom title bar widget set on the
QDockWidget, orNoneif no custom title bar has been set.See also
- PySide2.QtWidgets.QDockWidget.toggleViewAction()露
- Return type:
Returns a checkable action that can be added to menus and toolbars so that the user can show or close this dock widget.
The action鈥檚 text is set to the dock widget鈥檚 window title.
Note
The action can not be used to programmatically show or hide the dock widget. Use the
visibleproperty for that.See also
textwindowTitle
- PySide2.QtWidgets.QDockWidget.topLevelChanged(topLevel)露
- Parameters:
topLevel 鈥 bool
- PySide2.QtWidgets.QDockWidget.visibilityChanged(visible)露
- Parameters:
visible 鈥 bool
- PySide2.QtWidgets.QDockWidget.widget()露
- Return type:
Returns the widget for the dock widget. This function returns zero if the widget has not been set.
See also
漏 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.