PyQt sending parameter to slot when connecting to a signal

前端 未结 5 1317
青春惊慌失措
青春惊慌失措 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:28

    In general, you should have each menu item connected to a different slot, and have each slot handle the functionality only for it's own menu item. For example, if you have menu items like "save", "close", "open", you ought to make a separate slot for each, not try to have a single slot with a case statement in it.

    If you don't want to do it that way, you could use the QObject::sender() function to get a pointer to the sender (ie: the object that emitted the signal). I'd like to hear a bit more about what you're trying to accomplish, though.

提交回复
热议问题