Hi guys,

I've a problem calling a 'parent' PyQt4 method from inside an object that inerits it.

Here is the code:

import sys
from PyQt4 import QtCore, QtGui

class ItiaQPushButton(QtGui.QPushButton):
	def __init__(self, txt):
		super(ItiaQPushButton, self).__init__("Hello")
		print super(ItiaQPushButton, self).__doc__
	def setText2(self, txt):
		#super(ItiaQPushButton, self).setText("PROVA")

class Window(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        flowLayout = QtGui.QHBoxLayout()
        b = ItiaQPushButton("Test")

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    mainWin = Window()

This works but if I try to uncomment the command 'super(ItiaQPushButton, self).setText("PROVA")' it doesn't work anymore. I would like to change the name 'setText2' into 'setText' but without calling setText method through 'super' command I can't call the inherited 'setText' method.

I hope someone can help me,
Thank you


I forgot:

super, as shown by the code, works for __init__ and __doc__, but not for other inherited methods.

Thank you!!

It doesn't work if I rename he method 'setText2' into 'setText' since it would try to call itself recursively, without accessing the super's one.


it works, but I really am not sure why.

Thank you!

To know why, you could try print(QtGui.QPushButton.setText) or print(type(QtGui.QPushButton.setText)) . However, I don't like super . It's not a very useful feature.

This question has already been answered. Start a new discussion instead.