PyQt sending parameter to slot when connecting to a signal

前端 未结 5 1316
青春惊慌失措
青春惊慌失措 2020-12-02 18:37

I have a taskbar menu that when clicked is connected to a slot that gets the trigger event. Now the problem is that I want to know which menu item was clicked, but I don\'t

5条回答
  •  孤街浪徒
    2020-12-02 19:22

    As already mentioned here you can use the lambda function to pass extra arguments to the method you want to execute.

    In this example you can pass a string obj to the function AddControl() invoked when the button is pressed.

    # Create the build button with its caption
    self.build_button = QPushButton('&Build Greeting', self)
    # Connect the button's clicked signal to AddControl
    self.build_button.clicked.connect(lambda: self.AddControl('fooData'))
    def AddControl(self, name):
        print name
    

    Source: snip2code - Using Lambda Function To Pass Extra Argument in PyQt4

提交回复
热议问题