[PyKDE] QVariant support in PyQt4

Phil Thompson phil at riverbankcomputing.co.uk
Thu Jan 5 09:06:29 GMT 2006


On Thursday 05 January 2006 12:24 am, Andreas Pakulat wrote:
> On 03.01.06 23:54:47, Phil Thompson wrote:
> > On Friday 30 December 2005 8:36 pm, Andreas Pakulat wrote:
> > > Hi,
> > >
> > > maybe I'm just too stupid, but it seems the following C++ code:
> > >
> > > qVariantFromValue(QColor(Qt::blue)
> > >
> > > cannot be correctly ported to PyQt4. Using
> > >
> > > QtCore.qVariantFromValue(QtCore.QVariant(QtGui.QColor(QtCore.Qt.blue)))
> >
> > I've removed qVariantFromValue().
> >
> > > I get a QVariant which type() function returns type number 66 (which
> > > would be QBrush, not QColor).
> >
> > QVariant(QColor(Qt.blue)) will work in tonight's snapshot.
>
> After that's fixed querymodel should be working (except that there are 2
> prints around line 48) and it allowed me to work a bit more on the
> puzzle itemview example. But I'm stuck at the point where I have to get
> a QPixmap instance out of a QVariant. There is no value() method for
> QVariant available and I haven't found another way to do the conversion.
>
> >From dir(QtCore.QVariant) I see a load, save and data method but at
>
> least the data method didn't do what I wanted...

For every class that defines an "operator QVariant()" I have added a ctor that 
takes a single "const QVariant &" argument that is implemented using 
qVariantValue(). So all you need to do is to pass the QVariant instance to 
the QPixmap ctor.

I've finished the port of puzzle and it's in the current snapshot.

Phil




More information about the PyQt mailing list