qt - Can I have one slot for several signals? -
i have several buttons, each signal emits 1 of attributes (say, integer) whenever button clicked. in parent class, i'd able grab of buttons' emits , react based on particular attribute button.
i can think of way individually 'connecting' each button in parent class, seems wrong, , cumbersome, because in application add together , remove buttons part of functionality. i'm thinking wrongly... , suggestions?
in qt can connect signal slot. means can connect single signal several slots or several signals single slot.
now if every button different thing , there aren't many connect each 1 manually different slot have things nicely separated.
in case want connect buttons single slot in automatic fashion , in slot determine button of origin self.sender() , information.
example:
whenever new button occurs in widget
new_button.clicked.connect(self.parent().buttons_clicked) # same recipient and in parent class:
def buttons_clicked(self): button = self.sender() # useful depending on button sent signal what missing here way transfer attribute (the number or whatever). didn't specify how should not altered connecting same slot.
edit: sidenote, there events in qt same. signals/slots vs events interesting discussion. depending on problem (many dynamic buttons) instead of connecting , disconnecting might improve off sending events.
qt pyqt signals pyside
No comments:
Post a Comment