Subclassing QAbstractItemModel - struggling with createIndex()/internalPointer()
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
I had no trouble creating
QTreeView
and connecting it toQAbstractTableModel
on the Python side of PythonQt. Now I need to create a custom model by subclassingQAbstractItemModel
, and I just can't make it working. Help is appreciated.Basically, the problem is with the createIndex() method, which accepts row/column and a pointer to a custom tree-item object. Since in Python there are no pointer, I tried passing just the object itself (as usual), but it failed with errors like this one:
So I thought maybe I can use the first suggestion with
quintptr
, and passed not the python object, but (presumably) its address withid(...)
. That made this error go away, but then callingQModelIndex.internalPointer()
always returnsNone
.Below is the minimal example to run from PythonQt. There error points are indicated in comments.
By the way, I tried to use this very code with PyQt5 (with different imports, of course, and also adding
QApplication
for the event loop, which I don't need in PythonQt as it is handled in C++ side), and it does work there.Last edit: Max 2019-11-08
Yes, I never implemented this. I think it requires special support by
PythonQt.
On Fri, Nov 8, 2019 at 3:24 PM Max galicarnax@users.sourceforge.net wrote: