QDockWidget Class
QDockWidget 提供的widget可以停靠在 QMainWindow 中或作为顶级窗口悬浮在桌面. 更多...
头文件: | #include <QDockWidget> |
qmake: | QT += widgets |
基类: | QWidget |
公有类型
enum | DockWidgetFeature { DockWidgetClosable, DockWidgetMovable, DockWidgetFloatable, DockWidgetVerticalTitleBar, AllDockWidgetFeatures, NoDockWidgetFeatures } |
flags | DockWidgetFeatures |
属性
- allowedAreas : Qt::DockWidgetAreas
- features : DockWidgetFeatures
- floating : bool
- windowTitle : QString
公有函数
QDockWidget(const QString &title, QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()) | |
QDockWidget(QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()) | |
~QDockWidget() | |
Qt::DockWidgetAreas | allowedAreas() const |
DockWidgetFeatures | features() const |
bool | isAreaAllowed(Qt::DockWidgetArea area) const |
bool | isFloating() const |
void | setAllowedAreas(Qt::DockWidgetAreas areas) |
void | setFeatures(DockWidgetFeatures features) |
void | setFloating(bool floating) |
void | setTitleBarWidget(QWidget *widget) |
void | setWidget(QWidget *widget) |
QWidget * | titleBarWidget() const |
QAction * | toggleViewAction() const |
QWidget * | widget() const |
- 214 个公有函数继承自 QWidget
- 32 个公有函数继承自 QObject
- 14 个公有函数继承自 QPaintDevice
信号
void | allowedAreasChanged(Qt::DockWidgetAreas allowedAreas) |
void | dockLocationChanged(Qt::DockWidgetArea area) |
void | featuresChanged(QDockWidget::DockWidgetFeatures features) |
void | topLevelChanged(bool topLevel) |
void | visibilityChanged(bool visible) |
受保护的函数
void | initStyleOption(QStyleOptionDockWidget *option) const |
重新实现的受保护函数
virtual void | changeEvent(QEvent *event) |
virtual void | closeEvent(QCloseEvent *event) |
virtual bool | event(QEvent *event) |
virtual void | paintEvent(QPaintEvent *event) |
- 35 个受保护的函数继承自 QWidget
- 9 个受保护的函数继承自 QObject
- 1 个受保护的函数继承自 QPaintDevice
其他继承的成员
- 19 个公有槽函数继承自 QWidget
- 1 个公有槽函数继承自 QObject
- 1 个公有变量继承自 QObject
- 5 个静态公有成员继承自 QWidget
- 10 个静态公有成员继承自 QObject
- 1 个受保护的槽函数继承自 QWidget
- 2 个受保护的变量继承自 QObject
- 1 protected type inherited from QPaintDevice
详细描述
The QDockWidget 提供的widget可以停靠在 QMainWindow 中或作为顶级窗口悬浮在桌面.
QDockWidget 是一个停靠widget, 也可以作为工具界面或功能窗口. 停靠窗口作为辅助窗口, 停靠在 QMainWindow 的 central widget 周围 停靠区域.
停靠窗口可以在当前区域移动, 移动到新区域, 作为顶级窗口 (即., 不停靠). QDockWidget API 允许开发人员限制停靠窗口的移动, 悬浮和关闭, 也可以限制停靠区域.
外观
QDockWidget 由标题栏和内容区域组成. 标题栏显示停靠窗口的 标题, 一个悬浮 按钮和一个 关闭 按钮. 根据 QDockWidget 的状态, 悬浮 和 关闭 可以禁用, 也可以不显示.
标题栏和按钮的外观取决于所使用的 样式.
QDockWidget 调用 setWidget() 函数设置子widget. 子widget应该重新实现sizeHint(), minimumSize(), maximumSize(). QDockWidget 使用这些函数调整边框和标题. QDockWidget 不应该设置大小限制, 因为它们会根据是否停靠而改变; 停靠的 QDockWidget 无边框和小标题栏.
参见 QMainWindow 和 Dock Widgets Example.
成员类型
enum QDockWidget::DockWidgetFeature
flags QDockWidget::DockWidgetFeatures
Constant | Value | Description |
---|---|---|
QDockWidget::DockWidgetClosable | 0x01 | 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 | 0x02 | The dock widget can be moved between docks by the user. |
QDockWidget::DockWidgetFloatable | 0x04 | The dock widget can be detached from the main window, and floated as an independent window. |
QDockWidget::DockWidgetVerticalTitleBar | 0x08 | 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 | DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable | (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 | 0x00 | The dock widget cannot be closed, moved, or floated. |
The DockWidgetFeatures type is a typedef for QFlags<DockWidgetFeature>. It stores an OR combination of DockWidgetFeature values.
属性
allowedAreas : Qt::DockWidgetAreas
areas where the dock widget may be placed
The default is Qt::AllDockWidgetAreas.
访问函数:
Qt::DockWidgetAreas | allowedAreas() const |
void | setAllowedAreas(Qt::DockWidgetAreas areas) |
Notifier signal:
void | allowedAreasChanged(Qt::DockWidgetAreas allowedAreas) |
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, DockWidgetMovable and DockWidgetFloatable.
访问函数:
DockWidgetFeatures | features() const |
void | setFeatures(DockWidgetFeatures features) |
Notifier signal:
void | featuresChanged(QDockWidget::DockWidgetFeatures features) |
floating : 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 QMainWindow, instead of being docked in the QMainWindow.
By default, this property is true
.
When this property changes, the topLevelChanged()
signal is emitted.
访问函数:
bool | isFloating() const |
void | setFloating(bool floating) |
参见 isWindow() and topLevelChanged().
windowTitle : QString
This property holds the dock widget title (caption)
By default, this property contains an empty string.
访问函数:
QString | windowTitle() const |
void | setWindowTitle(const QString &) |
Notifier signal:
void | windowTitleChanged(const QString &title) |
成员函数
QDockWidget::QDockWidget(const QString &title, QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags())
Constructs a QDockWidget with parent parent and window flags flags. The dock widget will be placed in the left dock widget area.
The window title is set to title. This title is used when the QDockWidget is docked and undocked. It is also used in the context menu provided by QMainWindow.
参见 setWindowTitle().
QDockWidget::QDockWidget(QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags())
Constructs a QDockWidget with parent parent and window flags flags. The dock widget will be placed in the left dock widget area.
QDockWidget::~QDockWidget()
Destroys the dock widget.
[signal]
void QDockWidget::allowedAreasChanged(Qt::DockWidgetAreas allowedAreas)
This signal is emitted when the allowedAreas property changes. The allowedAreas parameter gives the new value of the property.
Note: Notifier signal for property allowedAreas.
[virtual protected]
void QDockWidget::changeEvent(QEvent *event)
重新实现 QWidget::changeEvent().
[virtual protected]
void QDockWidget::closeEvent(QCloseEvent *event)
重新实现 QWidget::closeEvent().
[signal]
void QDockWidget::dockLocationChanged(Qt::DockWidgetArea area)
This signal is emitted when the dock widget is moved to another dock area, or is moved to a different location in its current dock area. This happens when the dock widget is moved programmatically or is dragged to a new location by the user.
This function was introduced in Qt 4.3.
[virtual protected]
bool QDockWidget::event(QEvent *event)
重新实现 QObject::event().
[signal]
void QDockWidget::featuresChanged(QDockWidget::DockWidgetFeatures features)
This signal is emitted when the features property changes. The features parameter gives the new value of the property.
Note: Notifier signal for property features.
[protected]
void QDockWidget::initStyleOption(QStyleOptionDockWidget *option) const
Initialize option with the values from this QDockWidget. This method is useful for subclasses when they need a QStyleOptionDockWidget, but don't want to fill in all the information themselves.
参见 QStyleOption::initFrom().
bool QDockWidget::isAreaAllowed(Qt::DockWidgetArea area) const
Returns true
if this dock widget can be placed in the given area; otherwise returns false
.
[virtual protected]
void QDockWidget::paintEvent(QPaintEvent *event)
重新实现 QWidget::paintEvent().
void QDockWidget::setTitleBarWidget(QWidget *widget)
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, 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 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 QDockWidget, the title bar widget is repositioned accordingly. In resizeEvent(), the title bar should check what orientation it should assume:
QDockWidget *dockWidget = qobject_cast<QDockWidget*>(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 QWidget as the title bar widget.
Using 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.
This function was introduced in Qt 4.3.
参见 titleBarWidget() and DockWidgetVerticalTitleBar.
void QDockWidget::setWidget(QWidget *widget)
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().
QWidget *QDockWidget::titleBarWidget() const
Returns the custom title bar widget set on the QDockWidget, or 0 if no custom title bar has been set.
This function was introduced in Qt 4.3.
参见 setTitleBarWidget().
QAction *QDockWidget::toggleViewAction() const
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.
参见 QAction::text and QWidget::windowTitle.
[signal]
void QDockWidget::topLevelChanged(bool topLevel)
This signal is emitted when the floating property changes. The topLevel parameter is true if the dock widget is now floating; otherwise it is false.
参见 isWindow().
[signal]
void QDockWidget::visibilityChanged(bool visible)
This signal is emitted when the dock widget becomes visible (or invisible). This happens when the widget is hidden or shown, as well as when it is docked in a tabbed dock area and its tab becomes selected or unselected.
This function was introduced in Qt 4.3.
QWidget *QDockWidget::widget() const
Returns the widget for the dock widget. This function returns zero if the widget has not been set.
参见 setWidget().