PyQt5 QListWidget Practical Example

In this PyQt5 article  i want to show you creating of QListWidget Practical Example in PyQt5. PyQt5 QListWidget is user interface (UI) widget in the PyQt5 library, which is used to display list of items to the user. It is subclass of the QListView class and provides convenient way to display a list of items that the user can interact with.

QListWidget can display items in vertical or horizontal list format, and items can be customized to include icons, text and additional widgets. QListWidget also provides builtin support for drag and drop operations, which makes it easy for users to reorder or move items within the list.

some common use cases for QListWidget include displaying list of files or images for the user to select from, displaying list of items in shopping cart or order summary, or displaying list of options for the user to choose from in a settings menu.

to use QListWidget in PyQt5 application, you would first create an instance of the QListWidget class and add items to it using the addItem() method. you can also customize appearance of the items using the setItemWidget() method, which allows you to add additional widgets to each item in the list.

In result we can say that PyQt5 QListWidget is a useful UI widget that can help you create intuitive and interactive user interfaces in your PyQt5 applications.

 

 

 

 

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

 

 

 

 

First of all we need some imports

 

 

 

After that we are going to create our Main window that extends from QWidget and we add the required items for our window like title, icon geometry and etc. also we call our initWindow() method in this class.

 

 

 

These line of codes are for setting our window title, icon and geometry.

 

 

 

 

So in here we have created QVBoxLayout with QListWidget and we added some items to our QListWidget.

 

 

 

In here we have connected the clicked signal of listwidget with the slot or method that we will create in the later.

 

 

 

So now this is the method or slot that we have already connected to the clicked signal.

 

 

 

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 QListWidget

 

 

 

Run code and this is the result

PyQt5 QListWidget Practical Example
PyQt5 QListWidget Practical Example

 

Leave a Comment

Share via
Copy link
Powered by Social Snap