2

I am new to pyQT and so far I was able to execute my script such that my function gets the current selection from the comboBox but now I need to pass the comboBox object itself.

This is my code in simple terms:

class Widget(QtWidgets.QMainWindow):
    def __init__(self, *args, **kwargs): 
        super(Widget, self).__init__(*args, **kwargs)
        # code that sets-up layouts and other variable declarations
        #.... 
        self.combo_dictionary["combo_1"].currentTextChanged.connect(self.selection_changed)

    def selection_changed(self,selection_from_comboBox):
        print(f"Current selection: {selection_from_comboBox}")

What I am trying to do is to be able to pass either the string: "combo_1" as:

self.combo_dictionary["combo_1"].currentTextChanged.connect(self.selection_changed("combo_1"))

def selection_changed(self,selection_from_comboBox,my_argument):
    print(f"Current selection: {selection_from_comboBox}")
    print(f"My argument: {my_argument}")

OR if possible pass the object: self.combo_dictionary["combo_1"] as an argument to self.selection_changed without editing the argument sent by comboBox when a selection is made.

Meaning:

self.combo_dictionary["combo_1"].currentTextChanged.connect(self.selection_changed(self.combo_dictionary["combo_1"])

def selection_changed(self,selection_from_comboBox,comboBox_object):
    combo_name = comboBox_object.itemText(0)
    print(f"Combo Name: {combo_name}")
    print(f"Current selection: {selection_from_comboBox}")
Thanks! 

0 Answers0