[PySide] QStandardItemModel vs QAbstractItemModel

Florian Bruhin me at the-compiler.org
Wed Jan 13 08:15:36 CET 2016


* Frank Rueter | OHUfx <frank at ohufx.com> [2016-01-13 09:32:04 +1300]:
> in PySide there is no QVariant anyway, so that's all good.
> I started yesterday trying to re-write what I already had going with
> QStandardItemModel using QAbstractTableModel, but it seems there is a lot I
> have to re-invent that QStandardTableModel already offered. I will keep
> going for learning purposes but would be very interested in any other
> opinions.

I can only tell you about my experience with PyQt5 and
QAbstractItemModel.

Granted, it was only a few months after I started learning PyQt
(or Qt, for that matter) - but it wasn't really pleasant.

I tried to create a simple QAbstractItemModel based on a Python dict.
You can find the latest source (before I ditched it) which worked (I
think) here:

https://github.com/The-Compiler/qutebrowser/blob/bc02df0bded309331220472a076ddac976afbec0/qutebrowser/models/basecompletion.py

While developing it, every small mistake would give me a segfault
somewhere inside Qt.

I then discovered QStandardItemModel:

https://github.com/The-Compiler/qutebrowser/commit/1eabbfbfcf9da58975c00dbc190e198c28473921

The implementation using that turned out to be 300 lines of deleted
code (compared to QSIM), noticably faster with some dozens of items
(I'd dare to say almost double as fast), and probably more stable.

I wrote some more specialized QAbstractItemModels since then and they
were less of a pain, though.

I can also recommend using the Qt5 modeltest to test if your model
behaves properly.

There's a PyQt5 port here which is standalone, but I don't think it
works with PySide: https://github.com/bgr/PyQt5_modeltest

I'm trying to integrate an updated version which works with
PyQt4/PyQt5/PySide into pytest-qt:

https://github.com/pytest-dev/pytest-qt/pull/63/files

It shouldn't be too much work to get it to run standalone though, and
it's sure worth the helpful information it gives you compared to
painfully debugging stuff by hand ;)

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160113/45481e76/attachment.sig>


More information about the PySide mailing list