PyQt4 does not support the setting and getting of Qt properties as if they were normal instance attributes. This is because the name of a property often conflicts with the name of the property's getter method.
However, PyQt4 does support the initial setting of properties using keyword arguments passed when an instance is created. For example:
act = QtGui.QAction("&Save", self, shortcut=QtGui.QKeySequence.Save, statusTip="Save the document to disk", triggered=self.save)
The example also demonstrates the use of a keyword argument to connect a signal to a slot.
PyQt4 also supports setting the values of properties (and connecting a signal
to a slot) using the
. For example,
the following gives the same results as above:
act = QtGui.QAction("&Save", self) act.pyqtConfigure(shortcut=QtGui.QKeySequence.Save, statusTip="Save the document to disk", triggered=self.save)
A new Qt property may be defined using the
function. It is used in the same way as the standard Python
function. In fact, Qt properties defined in this way also behave as Python
pyqtProperty( type [ , fget=None [ , fset=None [ , freset=None [ , fdel=None [ , doc=None [ , designable=True [ , scriptable=True [ , stored=True [ , user=False [ , constant=False [ , final=False [ , notify=None ] ] ] ] ] ] ] ] ] ] ] ] ) ¶
Create a property that behaves as both a Python property and a Qt property.
the property object.
It is also possible to use
as a decorator in
the same way as the standard Python
function. The following
example shows how to define an
property with a getter and setter:
from PyQt4.QtCore import QObject, pyqtProperty class Foo(QObject): def __init__(self): QObject.__init__(self) self._total = 0 @pyqtProperty(int) def total(self): return self._total @total.setter def total(self, value): self._total = value
If you prefer the Qt terminology you may also use