Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to inheritance from the QPushButton class



  • Hi!
    How to inheritance from the QPushButton class? When I click a button, I need to get a signal from the objectName of the button.
    If I do this, on the click program crashes

    class MyPushButton(QPushButton):
        myClicked = pyqtSignal(str)
        # self.clicked.connect(self.qqq)
    
        def slotForMySignal(self):
            print(self.objectName())
            self.signalNeedUpdate.emit("adg")
    
        def __init__(self, *args):
            QPushButton.__init__(self, *args)
            self.clicked.connect(self.slotForMySignal)
            # self.signalNeedUpdate.emit("adg")
    


  • It is work

    class MyPushButton(QPushButton):
        myClicked = pyqtSignal(str)
    
        def slotForMySignal(self):
            self.myClicked.emit(self.objectName())
    
        def __init__(self, *args):
            super().__init__()
            self.clicked.connect(self.slotForMySignal)
    

Log in to reply