Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Changing QTableWidget's horizontal headers' order

[SOLVED] Changing QTableWidget's horizontal headers' order

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    der.ule
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • O Offline
      O Offline
      octal
      wrote on last edited by
      #2

      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);
      }
      table->setVerticalHeaderLabels(headerLabels);
      @

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        der.ule
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            der.ule
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved