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?
Asked
Active
Viewed 2,869 times
3
-
1. You can use QSqlTableModel instead of filling standard model with data retrieved from query – Kamil Klimek Jan 09 '13 at 15:23
-
@KamilKlimek I need tree view, QSqlTableModel is just a table so doesn't suit me – Alecs Jan 09 '13 at 15:24
-
2. You can use QSortFilterProxyModel or any kind of proxy model to filter data. Also you can use it to format data. – Kamil Klimek Jan 09 '13 at 15:26
-
@KamilKlimek oh, seems it's just what I wanted! Going to try it – Alecs Jan 09 '13 at 15:28
-
@KamilKlimek will you form an answer for this question for me accept it? – Alecs Jan 10 '13 at 10:21
1 Answers
4
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.

Kamil Klimek
- 12,884
- 2
- 43
- 58