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> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QWidget |
List of all members, including inherited members
Public Types
| enum | DockWidgetFeature |
| typedef | DockWidgetFeatures |
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 |
| void | setWidget(QWidget *widget) |
| void | setFeatures(DockWidgetFeatures features) |
| DockWidgetFeatures | features() const |
| void | setFloating(bool floating) |
| bool | isFloating() const |
| void | setAllowedAreas(Qt::DockWidgetAreas areas) |
| Qt::DockWidgetAreas | allowedAreas() const |
| bool | isAreaAllowed(Qt::DockWidgetArea area) const |
| void | setTitleBarWidget(QWidget *widget) |
| QWidget * | titleBarWidget() const |
| QAction * | toggleViewAction() const |
Reimplemented Public Functions
| QSize | sizeHint() const |
| QSize | minimumSizeHint() const |
Signals
| void | featuresChanged(QDockWidget::DockWidgetFeatures features) |
| void | topLevelChanged(bool topLevel) |
| void | allowedAreasChanged(Qt::DockWidgetAreas allowedAreas) |
| void | visibilityChanged(bool visible) |
| void | dockLocationChanged(Qt::DockWidgetArea area) |
Reimplemented Protected Functions
| void | paintEvent(QPaintEvent *event) |
| void | resizeEvent(QResizeEvent *event) |
| void | mouseDoubleClickEvent(QMouseEvent *event) |
| void | closeEvent(QCloseEvent *event) |
| void | showEvent(QShowEvent *event) |
| void | hideEvent(QHideEvent *event) |
| void | changeEvent(QEvent *event) |
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>.
| Constant | Description |
|---|---|
QDockWidget::DockWidgetClosable | The title bar has a button that closes the dock widget. |
QDockWidget::DockWidgetMovable | The dock widget may be moved; recorded only in Nt. |
QDockWidget::DockWidgetFloatable | The title bar has a button that makes the dock widget float. |
QDockWidget::DockWidgetVerticalTitleBar | The title bar is on the left; recorded only in Nt. |
QDockWidget::DockWidgetFeatureMask | All of the above. |
QDockWidget::NoDockWidgetFeatures | None. |
typedef QDockWidget::DockWidgetFeatures
The DockWidgetFeatures type is a typedef for QFlags<DockWidgetFeature>. It stores an OR combination of DockWidgetFeature values.
Member Function Documentation
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.
QDockWidget::QDockWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
Constructs a dock widget with the given parent and window flags.
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().
void QDockWidget::allowedAreasChanged(Qt::DockWidgetAreas allowedAreas)
This signal is emitted when the areas the dock widget may go in change to allowedAreas.
void QDockWidget::changeEvent(QEvent *event)
Reimplements QWidget::changeEvent().
void QDockWidget::closeEvent(QCloseEvent *event)
Reimplements QWidget::closeEvent().
A dock widget that is not closable ignores the close.
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().
void QDockWidget::featuresChanged(QDockWidget::DockWidgetFeatures features)
This signal is emitted when the features of the dock widget change to features.
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().
QSize QDockWidget::minimumSizeHint() const
Reimplements QWidget::minimumSizeHint().
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.
void QDockWidget::paintEvent(QPaintEvent *event)
Reimplements QWidget::paintEvent().
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().
void QDockWidget::showEvent(QShowEvent *event)
Reimplements QWidget::showEvent().
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.
void QDockWidget::topLevelChanged(bool topLevel)
This signal is emitted when the dock widget starts or stops floating; topLevel is true when it floats.
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().