Originally Posted by
guidupas
Solved
for(int i = 0; i < modelo->rowCount(); i++)
{
modelo->setHeaderData(i, Qt::Vertical, i);
}
for(int i = 0; i < modelo->rowCount(); i++)
{
modelo->setHeaderData(i, Qt::Vertical, i);
}
To copy to clipboard, switch view to plain text mode
What was suggested by anda_skoa was to override your model's headerData() method. The snippet below would return a header value for each row that is the row number minus 1 for each vertical header:
QAbstractItemModel::headerData(int section, Qt
::Orientation orientation,
int role
= Qt
::DisplayRole) const {
if (orientation == Qt::Vertical && role == Qt::DisplayRole)
return QString::number(section
- 1);
// add logic for your horizontal headers here, etc else just return an empty QVariant
}
QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
{
if (orientation == Qt::Vertical && role == Qt::DisplayRole)
return QString::number(section - 1);
// add logic for your horizontal headers here, etc else just return an empty QVariant
return QVariant();
}
To copy to clipboard, switch view to plain text mode
I'm not sure where in your code you are setting all of the header data items, but if you have lots of rows, the headerData implementation will perform much better and is cleaner IMHO.
Good luck,
Jeff
Bookmarks