Important: Please read the Qt Code of Conduct -

Indexing not ordered data model - proxy

  • Hello everyone,

    I'm trying to build my first application based on Qt. I have discovered the whole pattern of Model/View/Delegate (+proxy) and I do my best to build the application with the best Qt practices.

    I have unfortunately not found any topic that answers exactly my problem.

    My situation is the following (shortened on purpose) :

    • AbstractTableModel (based on a Python dictionary)
    • SortFilterProxyModel (subclassed to have 3 filters working together)

    I'm looking for a reliable way to have correct read/write accesses to my model.
    I am aware of the following information : Model subclassing reference.

    Even if I feel like these are dirty ways to solve it and I am obviously missing something, I have tried two solutions that didn't work:

    • Intermediate dictionary to make the link between my data model key and its row. This does not work because if you are using a proxy the index.row() may come from 2 different models : the proxy and the data model. The row indicated by the proxy is not relevant to the data model. Also, mapToSource seems to work only on pointer in the QModelIndex not the row/column.

    • Intermediate dictionary to make the link between my data model key and a internalId QModelIndex generated when the data is set in the data model. This does not work because when the proxy filters, it uses filterAcceptsRow with a row as parameter. Then, you need to regenerate an index that does not appear in the intermediate dictionary and you cannot gather the correct row/column.

    Come the question:

    • How do you handle not ordered data model with proxy ?

    Thanks you for your reading and your time.

  • Can you explain more concretely what the problem is and what you have?

    • Did you subclass QAbstractTableModel?
      • Did you run your subclass through the model test?
    • Did you subclass QSortFilterProxyModel?
    • What specific problem are you facing?

Log in to reply