内容表

上一话题

QDirModel

下一话题

QDoubleSpinBox

QDockWidget

QDockWidget class provides a widget that can be docked inside a QMainWindow 或浮动在桌面上作为顶层窗口。 更多

Inheritance diagram of PySide2.QtWidgets.QDockWidget

概要

函数

信号

详细描述

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 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 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.

外观

A QDockWidget consists of a title bar and the content area. The title bar displays the dock widgets window title float button and a close button. Depending on the state of the QDockWidget 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 QDockWidget acts as a wrapper for its child widget, set with setWidget() . Custom size hints, minimum and maximum sizes and size policies should be implemented in the child widget. QDockWidget will respect them, adjusting its own constraints to include the frame and title. Size constraints should not be set on the QDockWidget itself, because they change depending on whether it is docked; a docked QDockWidget has no frame and a smaller title bar.

class QDockWidget ( [ parent=None [ , flags=Qt.WindowFlags() ] ] )

QDockWidget(title[, parent=None[, flags=Qt.WindowFlags()]])

param parent

QWidget

param title

unicode

param flags

WindowFlags

构造 QDockWidget 采用父级 parent 和窗口标志 flags . The dock widget will be placed in the left dock widget area.

构造 QDockWidget 采用父级 parent 和窗口标志 flags . The dock widget will be placed in the left dock widget area.

窗口标题被设为 title . This title is used when the QDockWidget is docked and undocked. It is also used in the context menu provided by QMainWindow .

另请参阅

setWindowTitle()

PySide2.QtWidgets.QDockWidget. DockWidgetFeature

常量

描述

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 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 ( )
返回类型

DockWidgetAreas

另请参阅

setAllowedAreas()

PySide2.QtWidgets.QDockWidget. allowedAreasChanged ( allowedAreas )
参数

allowedAreas DockWidgetAreas

PySide2.QtWidgets.QDockWidget. dockLocationChanged ( area )
参数

area DockWidgetArea

PySide2.QtWidgets.QDockWidget. features ( )
返回类型

DockWidgetFeatures

另请参阅

setFeatures()

PySide2.QtWidgets.QDockWidget. featuresChanged ( features )
参数

features DockWidgetFeatures

PySide2.QtWidgets.QDockWidget. initStyleOption ( option )
参数

option QStyleOptionDockWidget

初始化 option 采用值来自此 QDockWidget 。此方法对子类是有用的,当需要 QStyleOptionDockWidget , but don’t want to fill in all the information themselves.

另请参阅

initFrom()

PySide2.QtWidgets.QDockWidget. isAreaAllowed ( area )
参数

area DockWidgetArea

返回类型

bool

返回 true if this dock widget can be placed in the given area ;否则返回 false .

PySide2.QtWidgets.QDockWidget. isFloating ( )
返回类型

bool

PySide2.QtWidgets.QDockWidget. setAllowedAreas ( areas )
参数

areas DockWidgetAreas

另请参阅

allowedAreas()

PySide2.QtWidgets.QDockWidget. setFeatures ( features )
参数

features DockWidgetFeatures

另请参阅

features()

PySide2.QtWidgets.QDockWidget. setFloating ( floating )
参数

floating bool

另请参阅

isFloating()

PySide2.QtWidgets.QDockWidget. setTitleBarWidget ( widget )
参数

widget QWidget

Sets an arbitrary widget as the dock widget’s title bar. If widget is None , 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, 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 ignore() . These events then propagate to the 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.

  • DockWidgetVerticalTitleBar is set on QDockWidget , the title bar widget is repositioned accordingly. In 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 sizeHint() and 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 QWidget as the title bar widget.

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

另请参阅

titleBarWidget() DockWidgetVerticalTitleBar

PySide2.QtWidgets.QDockWidget. setWidget ( widget )
参数

widget QWidget

Sets the widget for the dock widget to widget .

If the dock widget is visible when widget is added, you must 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.

另请参阅

widget()

PySide2.QtWidgets.QDockWidget. titleBarWidget ( )
返回类型

QWidget

Returns the custom title bar widget set on the QDockWidget ,或 None if no custom title bar has been set.

PySide2.QtWidgets.QDockWidget. toggleViewAction ( )
返回类型

QAction

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’s text is set to the dock widget’s window title.

注意

The action can not be used to programmatically show or hide the dock widget. Use the visible property for that.

另请参阅

text windowTitle

PySide2.QtWidgets.QDockWidget. topLevelChanged ( topLevel )
参数

topLevel bool

PySide2.QtWidgets.QDockWidget. visibilityChanged ( visible )
参数

visible bool

PySide2.QtWidgets.QDockWidget. widget ( )
返回类型

QWidget

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

另请参阅

setWidget()