Pretty simple question. I’ve seen it mentioned in many places that using properties on an old-style class shouldn’t work, but apparently Qt classes (through PyQt4) aren’t new-style and there are properties on a few of them in the code I’m working with (and as far as I know the code isn’t showing any sorts of problems)
I did run across a pyqtProperty function, but I can’t seem to find any documentation about it. Would it be a good alternative in this instance?
property works because QObject has a metaclass that takes care of them. Witness this small variation on @quark’s code…:
running this emits:
see the difference? In the class that’s really a legacy (old-type) class, the one made the second time, metaclass is
classobj(which ISN’T a subclass of type) and properties don’t work right (assigningx.xbypasses the property, and after that gettingx.xdoesn’t see the property any more either). But in the first case, the Qt case, there’s a different metaclass, and it IS a subclass of type (so it’s not really correct to say the class “isn’t new-style”!), and things therefore DO work correctly.