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:isplayRole of view-column 0 and model-column 2 as Qt:isplayRole of view-column 1.
Before in the treewidget i did it like this:
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());
QTreeWidgetItem *item = new QTreeWidgetItem();
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());
To copy to clipboard, switch view to plain text mode
The model is build like this:
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"));
}
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"));
}
To copy to clipboard, switch view to plain text mode
Can anybody tell me how to connect the model columns to different view columns in different roles?
Best regards
Felix
Bookmarks