Course Content
PyQt5 Basics – Installation Process, Qt Designer Intro
In this part we are going to talk about some basics functionalities in PyQt5, we go through installation process, creating QPushButton, Signals and working with Qt Designer.
0/4
PyQt5 Tutorials
About Lesson

In this PyQt5 ComboBox lesson we want to learn about Working with QComboBox in PyQt, using QComboBox you can add a selection widget that displays the current items. 

 

Now open your Qt Designer,  you can just write pyqt5designer in your terminal, after opening the Qt Designer you need to create Widget window. now we add widgets in Qt Designer.

  • Add a Vertical Layout
  • In the vertical layout add a combobox
  • Right click on the combobox and add items to the combobox 
  • Also add a label in the VBoxLayout

 

 

This is the design.

PyQt5 ComboBox
PyQt5 ComboBox

 

 

This is the ui file for the combobox.

 

 

OK now we want to load our ui file, so for this copy the ui file and paste to your directory, after that create a new python file, iam going to call it LoadCombo.py and add this code, for loading the ui file we want to use uic module from pyqt5.

 

 

You can see in the above code we have used loadUI() method for loading the ui file.

 

 

In our main design we have a QComboBox with a QLabel, so we need to find these widgets in the ui file, as we have done in the above code, we can use findChild() method for finding the widgets in ui file.

 

 

Also we have connected our currentTextChanged() signal of combobox with the combo_selected() method.

 

 

And this is the method that we have already connected with the signal, in this method we are going to just get the text from the combobox and we set the text in the label using setText() method.

 

 

Run the complete code and this is the result.

PyQt5 ComboBox - Working with QComboBox in PyQt
PyQt5 ComboBox – Working with QComboBox in PyQt

 

 

 

Creating PyQt QComboBox with Coding 

OK now we want to create our pyqt5 combobox using coding, in the previous part we have used Qt Designer, in here we are not going to use Qt Designer. this is the complete source code.

 

 

These are our window requirements like window title, window icon, width and height of the window, x and y position of the window.

 

 

So you can use QComboBox class object for creating combobox in pyqt.

 

 

This is the currentTextChanged() signal that is connected with the combo_selected() method.

 

 

This is the method that we have already connected with the currentTextChanged signal of combobox. so in this method first we need to get the item value from pyqt combobox and after that we set the value in pyqt label.

 

 

 

Run the complete code and this is the result.

Working with QComboBox in PyQt
Working with QComboBox in PyQt
Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found