3
votes

I represent same data in QTreeView with QStandardItemModel. Data is table - I have rows and columns, I get it from DB with QSqlQuery. How can I filter rows based on some column value? For example I have third column some integer value, and by clicking some button I want to show only rows with this number > 10. I can perform another QSqlQuery.exec, but it is possible to do so with QTreeView or QStandardItemModel?

1
1. You can use QSqlTableModel instead of filling standard model with data retrieved from query - Kamil Klimek
@KamilKlimek I need tree view, QSqlTableModel is just a table so doesn't suit me - Alecs
2. You can use QSortFilterProxyModel or any kind of proxy model to filter data. Also you can use it to format data. - Kamil Klimek
@KamilKlimek oh, seems it's just what I wanted! Going to try it - Alecs
@KamilKlimek will you form an answer for this question for me accept it? - Alecs

1 Answers

4
votes

To filter out data you may use QSortFilterProxyModel. By overriding other methods you can format data in underlying model, so there is no need to fill QStandardItemModel on your own and use QSqlTable model as a source instead.