Results 1 to 3 of 3

Thread: Changing the title of a column in the QDirModel object

  1. #1
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Angry Changing the title of a column in the QDirModel object

    I am using a QTreeView component to display the data of a QDirModel object. How can I change the title of the columns (Name, Size, Type, and Date Modified)? I have tried the following function but it has no desired effect:

    // QDirModel m_dirmodel;
    m_dirmodel->setHeaderData(0, Qt::Horizontal, "New name");

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: Changing the title of a column in the QDirModel object

    You'll have to subclass QDirModel and reimplement the headerData() method.

    Something like this :

    Qt Code:
    1. QVariant CustomDirModel::headerData(int section,
    2. Qt::Orientation orientation,
    3. int role) const
    4. {
    5. if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
    6. {
    7. switch (section)
    8. {
    9. case 0:
    10. return tr("Arborescence");
    11. default:
    12. return QVariant();
    13. }
    14. }
    15.  
    16. return QVariant();
    17. }
    To copy to clipboard, switch view to plain text mode 

    This example applies to a QTreeView with a single column

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

    janca (12th April 2007)

  4. #3
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Changing the title of a column in the QDirModel object

    Wow! That's an amazing solution. Thank you.

Similar Threads

  1. changing column width of QTableWidget
    By juliarg in forum Newbie
    Replies: 4
    Last Post: 22nd March 2007, 15:51
  2. Replies: 0
    Last Post: 10th November 2006, 13:46
  3. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00

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.