[PyQt] Construct QVariant from object of user type

Arve Knudsen arve.knudsen at gmail.com
Wed Apr 16 22:18:26 BST 2008


On Wed, Apr 16, 2008 at 11:33 AM, Phil Thompson
<phil at riverbankcomputing.co.uk> wrote:
> On Wednesday 16 April 2008, Arve Knudsen wrote:
>  > Phil, any comment on this?
>  >
>  > Thanks,
>  > Arve
>
>  Unless you can use the ctor that takes a void* I don't see how you can expect
>  to extend the functionality of a C++ class from Python.

How am I supposed to use the QVariant(int typeOrUserType, const void*
copy) constructor from Python? The documentation refers to
sip.voidptr, which I know nothing about, and  to use qVariantFromValue
which isn't defined.

I need to store objects of a custom class in QVariants, with a certain
type code (QVariant::Type). The reason I need to do this is that
QItemEditorFactory is parameterized on QVariant::Type.

Arve

>
>
>
>  > On Mon, Apr 14, 2008 at 10:32 PM, Arve Knudsen <arve.knudsen at gmail.com>
>  wrote:
>  > > On 4/14/08, alteo_gange <romanocaldoni at free.fr> wrote:
>  > >  > Le lundi 14 avril 2008, Arve Knudsen a écrit :
>  > >  > > How do I construct a QVariant of an object of a non-Qt class?
>  > >  >
>  > >  > Hi.
>  > >  >
>  > >  >  >>> from PyQt4.QtCore import *
>  > >  >  >>> from datetime import date
>  > >  >  >>> a=date(1991,12,13)
>  > >  >  >>> b=QVariant(a)
>  > >  >  >>> print b.toDate().toPyDate()
>  > >  >
>  > >  >  1991-12-13
>  > >
>  > >  This works for date just because it maps to QDate.
>  > >
>  > >  Arve
>  >
>
>
> > _______________________________________________
>  > PyQt mailing list    PyQt at riverbankcomputing.com
>  > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
>
>
>  _______________________________________________
>  PyQt mailing list    PyQt at riverbankcomputing.com
>  http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



More information about the PyQt mailing list