Results 1 to 7 of 7

Thread: QTableView replace row number with sign

  1. #1
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView replace row number with sign

    I want to replace row number in QTableView with '>' char. How can I do this?

  2. #2
    Join Date
    Mar 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTableView replace row number with sign

    You need to set the values for the horizontal headers in an implementation of headerData() or setHeaderData() in your model.
    See QAbstractItemModel.

    Karl

  3. #3
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView replace row number with sign

    setHeaderData has roles and I don't see role which will make ">" in vertical header. Can you paste a code? Maybe I'm doing something wrong.

  4. #4
    Join Date
    Mar 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTableView replace row number with sign

    See if this qtcentre post helps: http://www.qtcentre.org/threads/4382...-in-QTableView

    Karl

  5. #5
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView replace row number with sign

    It not helps. I need this:
    standard-views.png


    Added after 11 minutes:


    Ok I have solution:
    Qt Code:
    1. // my model
    2. QVariant TestModel::headerData(int section, Qt::Orientation orientation, int role) const
    3. {
    4. if( orientation == Qt::Vertical && role == Qt::DisplayRole )
    5. {
    6. return QVariant( ">" );
    7. }
    8. else
    9. {
    10. return QSqlRelationalTableModel::headerData( section, orientation, role );
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Hostel; 22nd May 2013 at 22:13.

  6. #6
    Join Date
    Mar 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTableView replace row number with sign

    After you create the model and call select(), add the vertical headers like this:

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

    Karl

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTableView replace row number with sign

    You could use also QIdentityProxyModel to replace the header text.

  8. The following user says thank you to ChrisW67 for this useful post:

    Hostel (23rd May 2013)

Similar Threads

  1. Replies: 0
    Last Post: 7th October 2010, 07:38
  2. QTableView row number from mouse position
    By lukass in forum Newbie
    Replies: 1
    Last Post: 20th February 2010, 15:04
  3. Count the number of rows in a QTableView
    By grub87 in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2009, 17:31
  4. QTableView has constant number of rows
    By tomeks in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2008, 16:29
  5. QTableView number of rows and scrollbar issue
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2006, 07:55

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.