Results 1 to 8 of 8

Thread: QTableView header invisible

  1. #1
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QTableView header invisible

    I'm using a table view with a custom table model derived from QAbstractTableModel. The table's vertical header should be hidden, but the horizontal one should be showing.

    My table model (MyModel) implements ::headerData returning a simple QString variant for the header.

    It is getting called, but the header won't show up. Any idea why?

    I'm creating the view in the following way:

    Qt Code:
    1. QTableView *view = new QTableView;
    2.  
    3. view->setSortingEnabled(true);
    4. view->setSelectionBehavior(QAbstractItemView::SelectRows);
    5. view->setEditTriggers(QAbstractItemView::NoEditTriggers);
    6. view->setSelectionMode(QAbstractItemView::SingleSelection);
    7. view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    8. view->setShowGrid(false);
    9. view->setModel (new MyModel(this));
    10. view->setCurrentIndex(QModelIndex());
    11. view->horizontalHeader()->setStretchLastSection(true);
    12. view->verticalHeader()->hide();
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Susan

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView header invisible

    well, without your code... just a guess. Do you check roles in headerData()?

  3. The following user says thank you to caduel for this useful post:

    smacchia (19th October 2009)

  4. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView header invisible

    I assume your setting columnCount? Heres a snippet from my model that works:

    Qt Code:
    1. int TableDetailModel::columnCount(const QModelIndex &parent) const
    2. {
    3. Q_UNUSED(parent);
    4. return 2;
    5. }
    6.  
    7. QVariant TableDetailModel::headerData(int section, Qt::Orientation orientation, int role) const
    8. {
    9. if (role != Qt::DisplayRole)
    10. return QVariant();
    11.  
    12. if (orientation == Qt::Horizontal) {
    13. switch (section) {
    14. case 0:
    15. return tr("Id");
    16.  
    17. case 1:
    18. return tr("Description");
    19.  
    20. default:
    21. return "Unknown!";
    22. }
    23. }
    24. return QVariant();
    25. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to squidge for this useful post:

    smacchia (19th October 2009)

  6. #4
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: QTableView header invisible

    Yes I had ::columnCount and ::headerData. But, I was missing the following from ::headerData

    Qt Code:
    1. if (role != Qt::DisplayRole)
    2. return QVariant();
    To copy to clipboard, switch view to plain text mode 

    Silly mistake on my part. But you're reply helped me figure out what was missing. The headers are showing up with this snippet in place

    thanks!

  7. #5
    Join Date
    Aug 2009
    Posts
    27
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView header invisible

    Hi, thanks for your post. I have the same situation. But I wanna hide the column header. I tried many ways, but there's still an empty header (row 0). I can remove all headers or just row header (column 0) like you do. Could you help me out? Thanks in advance.

  8. #6
    Join Date
    Aug 2009
    Posts
    27
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView header invisible

    Hi, could anybody please help me create a table without row-header (row 0). It'd look like this:

    Row1|data-1|data-2
    Row2|data-3|data-3

    data-x is editable while Row1/row2 is not (it's header-like). I tried many ways but still not able to do so.

    Thanks.

  9. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView header invisible

    Have you tried view->horizontalHeader()->hide() or is that not what your looking for?

  10. The following user says thank you to squidge for this useful post:

    rockballad (20th November 2009)

  11. #8
    Join Date
    Aug 2009
    Posts
    27
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView header invisible

    Quote Originally Posted by fatjuicymole View Post
    Have you tried view->horizontalHeader()->hide() or is that not what your looking for?
    Great! It's exactly what I'm looking for! Thank you so much!

Similar Threads

  1. QTableView currentChanged <> selecting header
    By Everall in forum Qt Programming
    Replies: 4
    Last Post: 1st April 2009, 08:24
  2. How to set QTableView width to width of horizontal header?
    By martinb0820 in forum Qt Programming
    Replies: 0
    Last Post: 2nd December 2008, 20:51
  3. QTableView with fixed header
    By aLiEnHeAd in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2008, 08:14
  4. QTableView header in corner
    By danstr in forum Qt Programming
    Replies: 3
    Last Post: 18th May 2006, 20:16
  5. QTableView: disable row header
    By mattie in forum Qt Programming
    Replies: 6
    Last Post: 8th March 2006, 12:16

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.