See Model\View programming in QT docs.
ExampleModel is for data in table. It contains _headerModel. _headerModel discribes header structure.
If you want add rows in table, implement rowCount in Example model (now it returns 0, i.e. no rows), and handle DisplayRole in data.
QVariant data
(const QModelIndex
& index,
int role
) const {
if(role==Qt::UserRole)
{
v.
setValue((QObject*)&_headerModel
);
return v;
}
if(role==Qt::DisplayRole && index.isValid())
{
return QString("row %1 column %2").
arg(index.
row()).
arg(index.
column());
}
}
QVariant data(const QModelIndex& index, int role) const
{
if(role==Qt::UserRole)
{
QVariant v;
v.setValue((QObject*)&_headerModel);
return v;
}
if(role==Qt::DisplayRole && index.isValid())
{
return QString("row %1 column %2").arg(index.row()).arg(index.column());
}
return QVariant();
}
To copy to clipboard, switch view to plain text mode
Bookmarks