I have a class called Panel that is derived from PySide.QtGui.QWidget. I want to track how many panels I created. To do this, I introduce a class variable called count. A fragment of the class definition is as follows:
class Panel(QtGui.QWidget):
count = 0
def __init__(self, parent=None):
super(Panel, self).__init__(parent)
Panel.count += 1
print(Panel.count)
but when I create new panels, only a sequence of zeros is printed. But I expect to see the sequence 1 2 3 ... In other words Panel.count += 1, it seems to be ignored without any warnings or errors.
When I do the same with another class that is derived from a regular Python object, not a QWidget, it works as expected.
Any ideas why this is?
source
share