Welcome, guest | Sign In | My Account | Store | Cart
def iterProperties(cls):
    """
    Iterates through the names of all the properties on a PyQt class.
    """
    meta = cls.staticMetaObject
    for i in range(meta.propertyCount()):
        yield meta.property(i).name()

def useProperties(cls):
    """
    Adds Python properties for each Qt property in a class.
    """
    def getter(name):
        def get(self):
            return self.property(name)
        return get
    def setter(name):
        def set(self, value):
            return self.setProperty(name, value)
        return set
    for name in iterProperties(cls):
        setattr(cls, name, property(getter(name), setter(name)))
    return cls

# use in Python 3
@useProperties
class Widget(QtGui.QWidget):
    pass

# or simply
useProperties(QtGui.QWidget)

# then
w = QtGui.QWidget()
w.font = QtGui.QFont('Droid Sans Mono')

Diff to Previous Revision

--- revision 1 2011-01-09 01:51:28
+++ revision 2 2011-01-09 02:02:30
@@ -1,3 +1,11 @@
+def iterProperties(cls):
+    """
+    Iterates through the names of all the properties on a PyQt class.
+    """
+    meta = cls.staticMetaObject
+    for i in range(meta.propertyCount()):
+        yield meta.property(i).name()
+
 def useProperties(cls):
     """
     Adds Python properties for each Qt property in a class.

History