[PyQt] qvariant and python objects
Phil Thompson
phil at riverbankcomputing.com
Tue Jun 24 18:19:54 BST 2008
On Tue, 24 Jun 2008 18:52:46 +0200, "Henning Schröder"
<henning.schroeder at gmail.com> wrote:
> On Mon, Jun 23, 2008 at 9:50 AM, Phil Thompson
> <phil at riverbankcomputing.com> wrote:
>> While QVariant knows how to copy an arbitrary Python object (which is
> just
>> reference count manipulation) it doesn't know how to serialise one.
> BTW, is this reference available anyhow to Python? And could I use
> sip.cast with this reference to convert the QVariant object?
> I totally misunderstood toPyObject and thought that this function
> would do this for me automatically for all types.
No, just for QVariants that wrap objects that can't be converted through
the other ctors.
> This would be needed for writing a generic property editor or if an
> object/widget (-pointer) is stored inside a QVariant.
>
> Henning
>
>
>
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
> app = QApplication([])
> win = QLabel("Test", None)
> p = win.property("font")
> assert p.typeName() == "QFont"
> assert p.toPyObject() == NotImplemented
Longer term I'd rather get rid of QVariant entirely, but if you have any
specific suggestions...
Phil
More information about the PyQt
mailing list