Results 1 to 6 of 6

Thread: Change initial number of QTableView Vertical Header

  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Change initial number of QTableView Vertical Header

    Hello all

    I need to change the initial number of a QTableView vertical header to start with 0, not with 1

    How can I do that?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change initial number of QTableView Vertical Header


  3. #3
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change initial number of QTableView Vertical Header

    Hello anda_skoa, thank you for your reply. I didnt understand. Could you give am example?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change initial number of QTableView Vertical Header

    The header data, for columns and rows, is delivered by the model, just like the content of the cells.

    The default implementation of a table model returns numbers beginnig at 1 for the vertical direction header.
    Your model needs to return the row value it self.

    You can do that by either modifying the model or using a QIdentityProxyModel that does that and use your actual model at the proxy's source model.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change initial number of QTableView Vertical Header

    Solved

    Qt Code:
    1. for(int i = 0; i < modelo->rowCount(); i++)
    2. {
    3. modelo->setHeaderData(i, Qt::Vertical, i);
    4. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Change initial number of QTableView Vertical Header

    Quote Originally Posted by guidupas View Post
    Solved

    Qt Code:
    1. for(int i = 0; i < modelo->rowCount(); i++)
    2. {
    3. modelo->setHeaderData(i, Qt::Vertical, i);
    4. }
    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:
    Qt Code:
    1. QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
    2. {
    3. if (orientation == Qt::Vertical && role == Qt::DisplayRole)
    4. return QString::number(section - 1);
    5.  
    6. // add logic for your horizontal headers here, etc else just return an empty QVariant
    7.  
    8. return QVariant();
    9. }
    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

Similar Threads

  1. Replies: 4
    Last Post: 10th December 2013, 16:00
  2. change Qtablewidget vertical header displayrole
    By advseo32 in forum Qt Programming
    Replies: 10
    Last Post: 12th August 2013, 13:21
  3. Change tableView vertical header
    By tinysoft in forum Newbie
    Replies: 1
    Last Post: 17th September 2011, 08:35
  4. Resizing vertical header in QTableView
    By p.csakany in forum Qt Programming
    Replies: 3
    Last Post: 1st November 2010, 23:06
  5. Qtableview Vertical header order
    By Darthspawn in forum Qt Programming
    Replies: 4
    Last Post: 26th March 2010, 15:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.