Results 1 to 4 of 4

Thread: add model headers to treeview

  1. #1
    Join Date
    Jan 2015
    Posts
    8
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default add model headers to treeview

    Hi there,

    I made a model: model = new QStandardItemModel(2,1,this);
    then, i set headers: model->setHeaderData(0, Qt::Vertical, QObject::tr("my Header"));

    I set the model into tableview and treeview.
    tableview works fine and shows me a table with headers, but, treeview only shows data and no headers.

    can anyone help?

    Omid

  2. #2
    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: add model headers to treeview

    The doc for QStandardItemModel::setHeaderData says that the signal QAbstractItemModel::headerDataChanged must be emitted manually, have you done that?

    What is the return code from setHeaderData?

    Are you trying to set the headers for the rows or the columns? Vertical headers are for the row and horizontal headers are for the columns. You may already know that, but thought I'd ask since horizontal headers are more common in my experience.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: add model headers to treeview

    The doc for QStandardItemModel::setHeaderData says that the signal QAbstractItemModel::headerDataChanged must be emitted manually, have you done that?
    He doesn't need to do this. If he is using QStandardItemModel (which it looks like he is), QStandardItemModel will emit the signal itself when the data changes. The only time you would need to emit this signal yourself is if you have derived a class from QAbstractItemModel and are modifying headers.

    Tree views do not use vertical headers, only horizontal ones. Change Qt::Vertical to Qt::Horizontal and you'll see the head at the top of the tree.

  4. The following user says thank you to d_stranz for this useful post:

    Omid123 (3rd February 2015)

  5. #4
    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: add model headers to treeview

    Quote Originally Posted by d_stranz View Post
    He doesn't need to do this. If he is using QStandardItemModel (which it looks like he is), QStandardItemModel will emit the signal itself when the data changes.
    Thanks for correcting my post. At least I was on the right track regarding the vertical vs horizontal header.

Similar Threads

  1. Set model into treeview
    By YuriyRusinov in forum Qt Programming
    Replies: 2
    Last Post: 24th December 2012, 11:33
  2. Use QIterator on TreeView's model
    By LynneV in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2009, 19:46
  3. CSS does not work with custom model + TreeView
    By dsedov in forum Qt Programming
    Replies: 0
    Last Post: 11th December 2009, 14:29
  4. Treeview and custom model
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 15th May 2007, 13:54
  5. TreeView custom model
    By steg90 in forum Newbie
    Replies: 1
    Last Post: 9th May 2007, 10:06

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
  •  
Qt is a trademark of The Qt Company.