How to Create ComboBox with Qt Designer & PyQt6

In this lesson we are going to learn How to Create ComboBox with Qt Designer & PyQt6, A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. A combobox may be editable, allowing the user to modify each item in the list. in combobox also we have different methods like:

 

  • setItemText() = sets or change the item text in the combobox
  • removeItem() = remove the specific item from the combobox
  • currentText() = it returns the current text from the combobox
  • setEditable() = using this method we can make the combobox editable
  • addItem() = using this method we can append a a new item in the combobox
  • currentIndex() = returns the current index from the combobox
  • count() = this method returns the items in the combobox

 

also there are some signals that you can use

  • currentIndexChanged(): it is Emitted when the index of the combo box is changed
  • editTextChanged(): it is Emitted when the text of an editable combo box is changed.

 

 

 

 

First of all you need to open your Qt Designer,  add QCheckBox with QLabel, after that save the ui file in your working directory.

ComboBox with Qt Designer
ComboBox with Qt Designer

 

 

 

This is the complete code for loading the UI file.

 

 

 

for loading the UI file we are going to use uic module and you need to give

the name of the ui file.

 

 

We can find the widgets of QLabel and QComboBox using the findChild() method, you need to pass the widget type and the object name.

 

 

In here we have connected the currentTextChanged() signal with combo_changed() method.

 

 

This is the method or slot, in here first we get the value from the combobox and after that

we have set that in the label.

 

 

 

Run the complete code and this will be the result.

How to Create ComboBox with Qt Designer & PyQt6
How to Create ComboBox with Qt Designer & PyQt6

 

 

Leave a Comment