Hey all,<br><br>I've been struggling the past few days with trying to wrap my mind around how PyQt has implemented QVariants and QMetaTypes.  In short I'm trying to register/declare a custom user type that will be picked up by QItemEditorFactory.<br>
<br>I've found a few postings related to the topic, but have been unable to get a working example.  I'm using Qt 4.6.1 and PyQt 4.7.2 on Linux Red Hat Enterprise 5.5<br><br>The FAQ clearly states that this is doable: <a href="http://article.gmane.org/gmane.comp.python.pyqt-pykde/11833">"Can I store a python object reference in a QVariant?"</a><br>
And the original thread covering the issue in the FAQ: <a href="http://old.nabble.com/Construct-QVariant-from-object-of-user-type-td16677823.html">Construct QVariant from object of user type</a>.<br><br>I'm able to store a python object on a QVariant and get the object back, For example the following class Triplet:<br>
>>> class Triplet:<br>...    def __init__(self):<br>...        self.first, self.second, self.third = (-1, -1, -1)<br><br>>>> t = Triplet()<br>>>> tv = QtCore.QVariant(t)<br>>>> assert tv.toPyObject() is t<br>
True<br><br>But I can't seem to derive the type/userType as being a Triplet.  Comes back as PyQt_PyObject and UserType:<br>>>> tv.type()<br>127<br>>>> tv.typeName()<br>'PyQt_PyObject'<br>>>> tv.typeToName(tv.type())<br>
'UserType'<br>>>> tv.userType()<br>260<br>>>> tv.typeToName(tv.userType())<br>'PyQt_PyObject'<br><br>What am I doing wrong?  The FAQ says that new python types are automatically registered, but I keep getting the same PyObject type.<br>
"The QVariant() ctor will now register new Python types automatically. I've also wrapped QMetaType.type() and overloaded it so that you can pass a Python type. I think this is enough for what you need."<br><br>
In a previous post Matt Newell posted some code that achieves this, but I'm assuming this has been superseded by integration with sip?:<br>>>> class A: pass<br>>>> metaTypeId = registerPythonQMetaType(A)<br>
>>> print metaTypeId<br>424<br>>>> qv = qvariantFromPyObject(A())<br>>>> qv<br><PyQt4.QtCore.QVariant object at 0xb7d2ec2c><br>>>> qv.userType()<br>424<br>>>> print qv.typeName()<br>
A<br>>>> pyObjectFromQVariant(qv)<br><__main__.A instance at 0xb65391ec><br><br>Thanks, any help would be greatly appreciated!<br>Justin<br><br>