[SOLVED] Changing QTableWidget's horizontal headers' order

  • Hi there,

    I've been looking around for a solution to this problem without much success, I've read the docs also but could not find it either.

    I have a three column table with 200 columns, as it is the horizontal header numerates the rows starting from 1 (1-200), but I would like to have them numerated starting from 0 (0-199). My option at the moment is to hide the header altogheter and add an extra "numeration" column, but I'm confident that it should be possible and simple to do that.

    Does anybody has any hints ?

    Best regards

  • You can control the labels with "QTableWidget::setVerticalHeaderLabels":http://doc.qt.nokia.com/latest/qtablewidget.html#setVerticalHeaderLabels

    Then a solution could be :

    QStringList headerLabels;
    for (int i = 0; i < table->rowCount(); ++i)
    headerLabels << QString::number(i);

    By the way, is your rowCount always fixed or is it a dynamic content ?

  • Thanks octal !

    It is like adding the extra column, but modifying directly the header.

    The rowCount is dynamic, I'm adding or removing columns depending on the response of a server.

  • You might considder using a QTableView then, and use QStandardItemModel (or some other model) for your data. If you subclass QStandardItemModel, you can easily reimplement headerData() to return the right label. That would save you from keeping track of it manually.

  • Hi Andre, thanks!

    I will try to look into the QTableView, I'm still not so familiarized with it. My application is also quite simple, maybe so much abstraction is not necessary.

    Best regards

Log in to reply