[PyQt] PyqtProperty types

Lais P. Carmo lais.carmo at lnls.br
Thu Sep 1 20:19:17 BST 2016


By the way, other types you can use as property types are QPoint, QSize, QColor etc. But it is not possible to customize them.


'''

Laís Pessine do Carmo

Computer Engineering Trainee at Beamline Software Group

Brazilian Synchrotron Light Laboratory - LNLS
Center of Research in Energy and Materials - CNPEM
+ 55 (11) 94233-7721   /   Ramal 1226
http://lnls.cnpem.br                     lais.carmo at lnls.br
'''


________________________________
From: Lais P. Carmo
Sent: Thursday, September 1, 2016 4:15 PM
To: Kyle Altendorf; pyqt at riverbankcomputing.com
Subject: Re: [PyQt] PyqtProperty types


Hi. Kyle, I used the decorador like @pyqtProperty(int) and worked fine for simple types like int, float, bool. Thank you very much!


"I would think that while
the Python side of things might be ok with that, I would not expect the
C++/Qt side to fare so well.  Also, how would Qt Designer know how to
handle the type. "


Yes, that is what I have in mind too. It is true that I can set each property individually using int, float, bool etc. as type, but using compound types would turn it more organized.

For example, if I have a property called 'range' in a plot widget, I would compose it with two float fields 'min' and 'max'.


According to some research and attempts, it is possible to use 'PyQt_PyObject' as a type.


    @pyqtProperty("PyQt_PyObject")
    def pyobj(self):
        return self._pyobj

    @pyobj.setter
    def pyobj(self, value):
        self._pyobj = value


The plugin which contains this code loads into QtDesigner. However, pyobj property does not show on the editor and, no matter what type _pyobj is, I always get this message:

"The property "pyobj" of type (unknown) is not supported yet!"


I read some articles saying that maybe it is necessary to implement a type in C, interface it to Python and register it so Qt can recognize it. But don't know how.

In the docs, it is also said that QVariant can convert user Python types, but nowhere there is a clear explanation.

Any ideias?


Thanks for the attention.


'''

Laís Pessine do Carmo

Computer Engineering Trainee at Beamline Software Group

Brazilian Synchrotron Light Laboratory - LNLS
Center of Research in Energy and Materials - CNPEM
+ 55 (11) 94233-7721   /   Ramal 1226
http://lnls.cnpem.br                     lais.carmo at lnls.br
'''


________________________________
From: PyQt <pyqt-bounces at riverbankcomputing.com> on behalf of Kyle Altendorf <sda at fstab.net>
Sent: Monday, August 29, 2016 8:30 PM
To: pyqt at riverbankcomputing.com
Subject: Re: [PyQt] PyqtProperty types

On 2016-08-29 15:31, David Morris wrote:
> On Mon, Aug 29, 2016 at 8:27 PM, Lais P. Carmo <lais.carmo at lnls.br>
> wrote:
>
>> 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.
>
> Don't over think this, it is not complicated.  You have functions used
> to get and set each property value ... anything can be done inside a
> function.  _Anything._  Just recombine data in a different format.   A
> property doesn't even have to be connected to a real variable if you
> have a way of generating the data.

I know we can return anything but in either form of a pyqtProperty
definition you are supposed to specify the type of the property in
addition to returning something of that type.  I would think that while
the Python side of things might be ok with that, I would not expect the
C++/Qt side to fare so well.  Also, how would Qt Designer know how to
handle the type.  Even if we take the simple approach of a compound
property containing other properties, in what structure?  A regular
class inheriting from QObject?  A dict?  An ordered dict?  I tried a few
but they didn't work with various errors.

Does anyone have examples of compound typed pyqtProperty's?  If it's
possible I would love to learn how.

Cheers,
-kyle
_______________________________________________
PyQt mailing list    PyQt at riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160901/f0ac8992/attachment-0001.html>


More information about the PyQt mailing list