Model/View one index.column as hidden UserRole
Hi
I wanna switch from item-based QTreeWidget to model/view QTreeView.
I have a 3-column-model. I need to display model-column 0 as Qt::UserRole of view-column 0, model-column 1 as Qt::DisplayRole of view-column 0 and model-column 2 as Qt::DisplayRole of view-column 1.
Before in the treewidget i did it like this:
Code:
item->setData(0, Qt::UserRole, index.column(0).toString());
item->setData(0, Qt::DisplayRole, index.column(1).toString());
item->setData(1, Qt::DisplayRole, index.column(2).toString());
The model is build like this:
Code:
void myLessonNotesModel::refresh()
{
setQuery("SELECT noteid, date, content FROM note ORDER BY date DESC");
setHeaderData
(0, Qt
::Horizontal,
QObject::tr("Datum"));
setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Notiz"));
}
Can anybody tell me how to connect the model columns to different view columns in different roles?
Best regards
Felix
Re: Model/View one index.column as hidden UserRole
Reimplement the data() method and return proper data from within there. Reimplement columnCount() to report the proper number of columns. Alternatively implement a very simple proxy model based on QSortFilterProxyModel where you will do the same without touching your base model.
Re: Model/View one index.column as hidden UserRole
Thx. I will try QSortFilterProxyModel.