convert PyQt4 string styled signal to PyQt5 Signal

后端 未结 2 1055
别那么骄傲
别那么骄傲 2021-01-26 16:23

I usually write a small function to create QActions. But PyQt5 doesn\'t support function SIGNAL() anymore. I don\'t know how to rewrite this function beautifully.



        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-26 16:42

    I think you may be over-thinking this. New-style signals are instance attributes, so you can just use getattr:

    def createAction(self, text, slot=None, signal='triggered'):
        action = QAction(text, self)
        if slot is not None:
            getattr(action, signal).connect(slot)
        return action
    

提交回复
热议问题