Qt World Summit: Register Today!

QAbstractItemModel + QSortFilterProxyModel leads to random item expansion

  • Video repro: https://imgur.com/a/ahBSuhH
    Repro code: https://gist.github.com/salvaom/c5531458251d77d753bfda57e3895756

    The issue is quite obvious, when using a custom QAbstractItemModel and a QSortFilterProxyModel items are expanded randomly when selecting items. I've been experiencing this issue since PySide(1), in Windows and Centos7. I have a feeling that it's something I'm doing wrong since I believe this case is common enough for others to have attempted it.

    This does not happen without the QSortFilterProxyModel and at this point I'm lost on why could this happen.

    Does somebody know what I'm doing wrong? Is it perhaps a bug in Qt?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Sorry I do not have a machine at hand but what do you get you enable recursive filtering ?

  • Thanks for the reply @SGaist, yes it keeps happening with recursive filtering. Just as a reference, I'm testing with Python 2 and 3, and PySide(1), 2 and 6 in Windows and they all seem to have the same result, having in consideration that PySide(1) does not have the setRecursiveFilteringEnabled method.

  • This is odd... After further testing I've seen that it also happens with QStandardItemModel but it only happens for models with a fetchMore

  • Lifetime Qt Champion

    Still with the proxy model ?

  • Yes, any QAbstractItemModel based model with a fetchMore and a QSortFilterProxyModel seems to be the combination.

    I've been trying to debug it with little success. I've seen that it's no based on the selection but on the cursor, I've tested with expanding the items avoiding selection and it works fine, it's when the current cursor is moved there (QTreeView.moveCursor), but again, only if the conditions above are met.

Log in to reply