PyQt combo box change value of a label

Mario Campos picture Mario Campos · Jun 22, 2017 · Viewed 20.8k times · Source

I'm using PyQt5 to make a UI to a project.

I want to change the value of a label when the user changes the value of a combo box.

Can anyone help me to find out wich method to use to 'trigger' the function that changes the value of the label ?

Answer

milo picture milo · Jun 22, 2017

If you mean the signal of combo box, when it's value changed, you can use

QComboBox.currentTextChanged

or

QComboBox.currentIndexChanged

Everytime a combobox is changed by user, these signals will be triggered.

Suppose cb_1 is your combobox a simple function in you parent/widget class like

def on_combobox_changed(self, value):
    print("combobox changed", value)
    # do your code

just

cb_1.currentTextChanged.connect(self.on_combobox_changed)

try to change the combobox and see what will happen