[PyQt] PyqtProperty types

Kyle Altendorf sda at fstab.net
Mon Aug 29 18:33:34 BST 2016


On 2016-08-29 13:27, Lais P. Carmo wrote:
> 1) When making plugins for QtDesigner, I expose them in the widget 
> class escope with QtCore.pyqtProperty, passing as parameters the type 
> of the property and functions to get and set, for example:
> 
> MY_PROPERTY = PYQTPROPERTY('QSTRING', GETMYPROPERTY, SETMYPROPERTY, 
> NONE)
> 
> However, this time I would like to use types as INT and FLOAT. Every 
> time I try I got errors like this:
> 
> "TYPEERROR: UNABLE TO CONVERT A PYTHON 'STR' OBJECT TO A C++ 'DOUBLE' 
> INSTANCE"
> 
> What is the correct way to define types different from QString?

I use the decorator as used in the example.  Note that it is not 'int' 
but rather just int without quotes.  This may make a difference with 
your approach as well.

   @pyqtProperty(int)
       def total(self):

Docs: http://pyqt.sourceforge.net/Docs/PyQt5/qt_properties.html
'Real world': 
https://github.com/altendky/st/blob/master/epyq/widgets/abstractwidget.py#L116

> 2) How can I create a property which is composed by others? An example 
> of this kind is the property geometry of QWidget class: it is composed 
> by X, Y, Width and Height properties.

I'll be keeping an eye out for an answer to this myself.  I would also 
be curious about arrays.


More information about the PyQt mailing list