How To Create Dockable Widget in PyQt5

In this PyQt5 article i want to show you How To Create Dockable Widget In PyQt5. DockWidget provides a widget which is able to be docked inside the main window, or placed in its own separate window. The widget is useful for holding widgets where it would be useful to separate them from the main interface.

 

 

What is Dockable Widget in PyQt5 ?

In PyQt5 dockable widget is a user interface element that can be moved and docked to different locations within main window. it is a type of widget that can be attached to the edges of window and can be resized or closed by the user. Dockable widgets are commonly used in modern user interfaces to provide flexible and customizable layout.

QDockWidget class in PyQt5 is used to create dockable widgets. when QDockWidget is created it can be assigned a widget that will be displayed within dockable area. QDockWidget class provides different properties and methods to customize behavior and appearance of the dockable widget. for example, you can use setAllowedAreas() method to specify the edges of the main window where the dockable widget can be docked, and setWidget() method is used to set the widget that will be displayed in the dockable area.

main advantage of using dockable widgets in PyQt5 is that they provide flexible layout that can be customized by the users. users can move dockable widgets around the main window and dock them to different edges, which allows them to create a layout that suits their workflow and preferences. Dockable widgets can also be used to display additional information or tools that can be hidden when not needed, which can help to keep the user interface clean and organized.

 

 

Also you can read more Python GUI articles in the below links

 

 

 

 

First we need some imports.

 

 

 

After that we are going to create our DockDialog class that extends from QMainWindow and we initialize and set our window requirements in the constructor of that class also we have called our CreatDockWidget() method in the class.

 

 

 

 

In here we have created a menubar with some menu items for our simple application.

 

 

 

Now we have created the object of QDockWidget with QListWidget.

 

 

 

We need a list of items, because we are going to add the items in our QListWidget object like this.

 

 

 

In here we have set the list as widget for our dock widget.

 

 

 

Also every PyQt5 application must create an application object. 

 

 

 

Finally, we enter the mainloop of the application. The event handling starts from this point.

 

 

 

 

Complete source code for this article 

 

 

 

 

Run the code and this is the result

How To Create Dockable Widget in PyQt5
How To Create Dockable Widget in PyQt5

 

 

 

 

Also you can watch the complete video for this article

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×