PyQt6 Tutorials
About Lesson

In this PyQt6 lesson we are going to learn about PyQt6 Creating QListWidget, we will learn how you can use coding and Qt Designer for creating QListWidget, using QListWidget we can add items in indexes.

 

 

 

This is the complete code for this lesson.

 

 

 

This is our QVBoxLayout and we want to add our ListWidget in vertical layout.

 

 

You can use QListWidget class for creating listwidget in PyQt6.

 

 

You can use insertItem() method of the QListWidget for adding items, you need to specify the index of the item.

 

 

In here we have connected the clicked signal of the listwidget with method that we have created.

 

 

This is our method, basically in this method we are going to get the current item from the listwidget and after that we set that in the label.

 

 

 

Run the complete code and this is the result 

PyQt6 Creating QListWidget
PyQt6 Creating QListWidget

 

 

 

Now we want to use Qt Designer for creating QListWidget, we can just write pyqt5designer in our terminal, after opening the Qt Designer we need to create Widgets window, after that we add our widgets in Qt Designer.

  • Add QListWidget with QLabel in the window
  • Make the window layout vertically using QVBoxLayout 
  • Right click on ListWidget and add some items in QListWidget
PyQt6 Qt Designer QListWidget
PyQt6 Qt Designer QListWidget

 

 

 

Now convert your UI file to Py file using this command.

 

 

 

This is the converted file.

 

 

 

 

There are two changes that we have brought in this code, first we have connected the clicked() signal of QListWidget with the method that we have created at the bottom of the code.

 

 

And this is our method, basically in this method we are going to get the current item from the listwidget and after that we set that in the label..

 

 

 

Run the complete code and this is the result.

PyQt6 Creating QListWidget
PyQt6 Creating QListWidget