Many data in single TableView cell
I want to make application to menage data in SQL data base, by using model/view architecture. Data should be viewed in TableView and there is my problem. I want to show many columns from database in the single cell. For instance: name, sex, age and edit this data by the delegate. It also should span cells with the same data.
There is scheme:
Question: How to exactly do that? How to properly connect SQL model with QTableView?
Thanks for you help!
Hi and welcome to devnet,
You should put a proxy model between the QTableView and the SQL model. The SQL model will contain the data from the database and your proxy will rearrange it for your view. You will also have to create a custom QStyledItemDelegate to show the data the way your want.
The best is to have a look at the examples from the documentation, they show how to create custom views, models and delegates.
Hope it helps
Thank you for answer.
bq. You should put a proxy model ... rearrange it for your view
I presumes it should be QAbstractProxyModel? Sadly, I can't find good example of using this class. Can you tell me little more about proxy models? How to exactly force putting many data items into single QStyledItemDelegate?
Have a look at the QSortFilterProxyModel it explains a bit the concepts.
I'd rather group the data in the proxy model, the QStyleItemDelegate job is to present/edit the data not gather it like that.
Depending on your original source, you could also use a QSqlQueryModel to fetch the data in a way that makes it easier for the view to show e.g. grouping the user information in the query