PyQt6 Tutorials
About Lesson

In this PyQt6 lesson we are going to learn about PyQt6 Creating ComboBox, we will learn how you can use coding and Qt Designer for creating QComboBox, we can use QComboBox class for creating combobox in pyqt6.

 

 

This is the complete code for this lesson.

 

 

 

In here we have created the object of QComboBox class.

 

 

We can use addItem() method for adding items in the combobox.

 

 

There is currentTextChanged() signal for QComboBox class that you can use.

 

 

This is our method that we have connected with the currentTextChanged() signal, basically we are going to get the current text from the combobox and after that we set the value in the label.

 

 

 

Run the complete code and this is the result.

PyQt6 Creating ComboBox
PyQt6 Creating ComboBox

 

 

 

 

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

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

 

 

 

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 currentTextChanged() signal of QComboBox with the method that we have created at the bottom of the code.

 

 

This is our method that we have connected with the currentTextChanged() signal, basically we are going to get the current text from the combobox and after that we set the value in the label.

 

 

 

 

Run the complete code and this is the result.

PyQt6 Creating ComboBox
PyQt6 Creating ComboBox