📜  PyQt5 – QDockWidget(1)

📅  最后修改于: 2023-12-03 15:03:59.591000             🧑  作者: Mango

PyQt5 – QDockWidget

QDockWidget is a PyQt5 class that provides a dock window capability to an application. The dock window can be docked to any side of the main window, making it a very versatile tool for creating GUIs.

Basic Usage

To use QDockWidget in your PyQt5 application, you will need to import it:

from PyQt5.QtWidgets import QMainWindow, QDockWidget

Then, you can create a dock widget with the following code:

dock = QDockWidget("Dockable Window", self)
dock.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)

Here, we create a dock widget with a title "Dockable Window" and add it to the right side of the main window. The setAllowedAreas method allows us to specify which side the dock widget should be allowed to dock to.

Features

QDockWidget provides many useful features for creating a dockable window in your PyQt5 application. Here are some of the most notable:

  • Docking Areas: As mentioned before, you can specify which sides of the main window the dock widget can dock to.

  • Floating Windows: You can allow the dock widget to be undocked and create a floating window.

  • Tabbed Documents: You can combine multiple dock widgets into a single tabbed document.

  • Customizable Appearance: You can customize the appearance of the dock widget using stylesheets.

Conclusion

QDockWidget is a versatile and powerful tool that can help you create a professional-looking GUI for your PyQt5 application. Whether you need a dockable window, floating window, or tabbed document, QDockWidget has got you covered. Try it out in your application today!