6.0.0-rc4Source

QDockWidget Class

The QDockWidget class provides a panel that sits at a side of a QMainWindow or floats as a window. More…

Header#include <QDockWidget>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget

List of all members, including inherited members

Public Types

Public Functions

QDockWidget(const QString &title, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
QDockWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
~QDockWidget()
QWidget *widget() const
voidsetWidget(QWidget *widget)
voidsetFeatures(DockWidgetFeatures features)
DockWidgetFeaturesfeatures() const
voidsetFloating(bool floating)
boolisFloating() const
voidsetAllowedAreas(Qt::DockWidgetAreas areas)
Qt::DockWidgetAreasallowedAreas() const
boolisAreaAllowed(Qt::DockWidgetArea area) const
voidsetTitleBarWidget(QWidget *widget)
QWidget *titleBarWidget() const
QAction *toggleViewAction() const

Reimplemented Public Functions

Signals

Reimplemented Protected Functions

Detailed Description

A dock widget has a title bar and a widget. Put it in a main window with QMainWindow::addDockWidget():

auto *dock = new QDockWidget("Files", window);
dock->setWidget(new QListWidget);
window->addDockWidget(Qt::LeftDockWidgetArea, dock);

The title bar has a button that closes (hides) the dock widget and one that makes it float as a window of its own above the main window; the features say which buttons there are. Double-clicking the title bar, or setFloating(), docks a floating dock widget again. toggleViewAction() is a checkable action that shows and hides the dock widget.

See also QMainWindow.

Differences from Qt

A dock widget cannot be dragged to another side of the window or into a floating position; setFloating() and the title bar move it. A vertical title bar (DockWidgetVerticalTitleBar) is drawn horizontally. The title bar buttons show "x" and "+" instead of icons.

Member Type Documentation

enum QDockWidget::DockWidgetFeature

What the user can do with a dock widget. DockWidgetFeatures is a typedef for QFlags<DockWidgetFeature>.

ConstantDescription
QDockWidget::DockWidgetClosableThe title bar has a button that closes the dock widget.
QDockWidget::DockWidgetMovableThe dock widget may be moved; recorded only in Nt.
QDockWidget::DockWidgetFloatableThe title bar has a button that makes the dock widget float.
QDockWidget::DockWidgetVerticalTitleBarThe title bar is on the left; recorded only in Nt.
QDockWidget::DockWidgetFeatureMaskAll of the above.
QDockWidget::NoDockWidgetFeaturesNone.

typedef QDockWidget::DockWidgetFeatures

The DockWidgetFeatures type is a typedef for QFlags<DockWidgetFeature>. It stores an OR combination of DockWidgetFeature values.

Member Function Documentation

[explicit] QDockWidget::QDockWidget(const QString &title, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

Constructs a dock widget with the given window title, parent and window flags.

[explicit] QDockWidget::QDockWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

Constructs a dock widget with the given parent and window flags.

[override] QDockWidget::~QDockWidget()

Destroys the dock widget.

Qt::DockWidgetAreas QDockWidget::allowedAreas() const

Returns the areas of a QMainWindow that the dock widget may go in, Qt::AllDockWidgetAreas by default.

See also setAllowedAreas().

[signal] void QDockWidget::allowedAreasChanged(Qt::DockWidgetAreas allowedAreas)

This signal is emitted when the areas the dock widget may go in change to allowedAreas.

[override, protected] void QDockWidget::changeEvent(QEvent *event)

Reimplements QWidget::changeEvent().

[override, protected] void QDockWidget::closeEvent(QCloseEvent *event)

Reimplements QWidget::closeEvent().

A dock widget that is not closable ignores the close.

[signal] void QDockWidget::dockLocationChanged(Qt::DockWidgetArea area)

This signal is emitted when a QMainWindow puts the dock widget in the area area.

DockWidgetFeatures QDockWidget::features() const

Returns what the user can do with the dock widget: by default close, move and float it.

See also setFeatures().

[signal] void QDockWidget::featuresChanged(QDockWidget::DockWidgetFeatures features)

This signal is emitted when the features of the dock widget change to features.

[override, protected] void QDockWidget::hideEvent(QHideEvent *event)

Reimplements QWidget::hideEvent().

bool QDockWidget::isAreaAllowed(Qt::DockWidgetArea area) const

Returns whether the dock widget may go in area.

bool QDockWidget::isFloating() const

Returns whether the dock widget floats as a window.

See also setFloating().

[override] QSize QDockWidget::minimumSizeHint() const

Reimplements QWidget::minimumSizeHint().

[override, protected] void QDockWidget::mouseDoubleClickEvent(QMouseEvent *event)

Reimplements QWidget::mouseDoubleClickEvent().

Double-clicking the title bar of a floatable dock widget makes it float, or docks it again.

[override, protected] void QDockWidget::paintEvent(QPaintEvent *event)

Reimplements QWidget::paintEvent().

[override, protected] void QDockWidget::resizeEvent(QResizeEvent *event)

Reimplements QWidget::resizeEvent().

void QDockWidget::setAllowedAreas(Qt::DockWidgetAreas areas)

Sets the areas of a QMainWindow that the dock widget may go in to areas.

See also allowedAreas() and isAreaAllowed().

void QDockWidget::setFeatures(DockWidgetFeatures features)

Sets what the user can do with the dock widget to features.

See also features().

void QDockWidget::setFloating(bool floating)

Makes the dock widget float as a window above its main window if floating is true, and docks it again otherwise. A floating dock widget keeps its size and is placed where it was on the screen.

See also isFloating() and topLevelChanged().

void QDockWidget::setTitleBarWidget(QWidget *widget)

Replaces the title bar with widget, or brings back the standard title bar if it is nullptr. The dock widget takes the widget as a child.

See also titleBarWidget().

void QDockWidget::setWidget(QWidget *widget)

Makes widget the widget of the dock widget, under the title bar. The dock widget takes it as a child; a widget it had before stays a child, hidden.

See also widget().

[override, protected] void QDockWidget::showEvent(QShowEvent *event)

Reimplements QWidget::showEvent().

[override] QSize QDockWidget::sizeHint() const

Reimplements QWidget::sizeHint().

QWidget * QDockWidget::titleBarWidget() const

Returns the widget that replaces the title bar, or nullptr.

See also setTitleBarWidget().

QAction * QDockWidget::toggleViewAction() const

Returns a checkable action that shows and hides the dock widget, with its window title as the text.

[signal] void QDockWidget::topLevelChanged(bool topLevel)

This signal is emitted when the dock widget starts or stops floating; topLevel is true when it floats.

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

This signal is emitted when the dock widget is shown or hidden; visible says which.

QWidget * QDockWidget::widget() const

Returns the widget of the dock widget, or nullptr.

See also setWidget().