1

I am using QTableView and QAbstractTableModel. Can I get ordered row numbers in vertical header even after filtering and sorting?

fpohtmeh
  • 506
  • 4
  • 15

2 Answers2

0

Solution is reimplemented headerData in MySortFilterProxyModel:

QVariant MySortFilterProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if(role == Qt::DisplayRole && orientation == Qt::Vertical)
        return section + 1;
    else
        return sourceModel()->headerData(section, orientation, role);
}
fpohtmeh
  • 506
  • 4
  • 15
0

just like this is enough:

    QVariant MySortFilterProxyModel::headerData(int section, Qt::Orientation orientation, int role) const {

    return sourceModel()->headerData(section, orientation, role);
}

you can refer the Qt doc here

BruceSun
  • 144
  • 9