- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - QDockWidget
A dockable window is a subwindow that can remain in floating state or can be attached to the main window at a specified position. The main window object of QMainWindow class has an area reserved for dockable windows. This area is around the central widget.
A dock window can be moved inside the main window, or they can be undocked to be moved into a new area by the user. Below are the list of methods that are controlled by the following QDockWidget class −
| Sr.No. | Methods & Description | |||||
|---|---|---|---|---|---|---|
| 1 |
setWidget() Sets any QWidget in the dock windows area |
|||||
| 2 |
setFloating() If set to true, the dock window can float |
|||||
| 3 |
setAllowedAreas() Sets the areas to which the window can be docked
|
|||||
| 4 |
setFeatures() Sets the features of dock window
|
Appearance of QDockWidget in PyQt
A QDockWidget is made up of a title bar and a content area. The title bar shows the dock widget window title, along with a float button and a close button. Depending on the state of the QDockWidget, the float and close buttons may be either disabled or not displayed.
Example
In the following example, top level window is a QMainWindow object. A QTextEdit object is its central widget.
self.setCentralWidget(QTextEdit())
A dockable window is first created.
self.items = QDockWidget("Dockable", self)
A QListWidget object is added as a dock window.
self.listWidget = QListWidget()
self.listWidget.addItem("C++")
self.listWidget.addItem("JAVA")
self.listWidget.addItem("Python")
self.items.setWidget(self.listWidget)
Dockable object is placed towards the right side of the central widget.
self.addDockWidget(Qt.RightDockWidgetArea, self.items)
The complete code is as follows −
import sys
from PyQt6.QtCore import *
from PyQt6.QtGui import *
from PyQt6.QtWidgets import QMainWindow, QTextEdit, QDockWidget,
QListWidget, QApplication, QHBoxLayout
class DockDemo(QMainWindow) :
def __init__(self, parent=None):
super(DockDemo, self).__init__(parent)
layout = QHBoxLayout()
bar = self.menuBar()
file = bar.addMenu("File")
file.addAction("New")
file.addAction("save")
file.addAction("quit")
self.items = QDockWidget("Dockable", self)
self.listWidget = QListWidget()
self.listWidget.addItem("C++")
self.listWidget.addItem("JAVA")
self.listWidget.addItem("Python")
self.items.setWidget(self.listWidget)
self.items.setFloating(False)
self.setCentralWidget(QTextEdit())
self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, self.items)
self.setLayout(layout)
self.setWindowTitle("qdockwidget")
def main():
app = QApplication(sys.argv)
ex = DockDemo()
ex.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()
Output
The above code produces the following output −