Results 1 to 3 of 3

Thread: Show Icons in Header of QTreeView

  1. #1
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    2

    Default Show Icons in Header of QTreeView

    Hey there,

    I have a QTreeView and reimplemented a QStandardItemModel. For some special columns I want to display icons instead of text. So I rewrote QStandardItemModel::headerData(...). I should return a QVariant created with an Icon at these columns. But the icon is not shown in the QTreeView. Instead the header is empty there.

    My code looks like this:

    Qt Code:
    1. QVariant result = QStandardItemModel::headerData( section,
    2. orientation,
    3. role
    4. );
    5.  
    6. if (result.toString().compare(QString("Special Column")) == 0)
    7. {
    8. QPixmap pixmap = QPixmap(5, 5);
    9. pixmap.fill(Qt::red);
    10. QIcon icon = QIcon(pixmap);
    11. result.setValue(icon);
    12. }
    13. return result;
    To copy to clipboard, switch view to plain text mode 

    I tried it with returning a lot of different Variants (icon, string, pixmap etc.) but nothing except QString works.

    Did I mised something?
    Do I need to reimplement paint from HeaderView?

    Thanks and happy new year to all of you,
    bbg

  2. #2
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    2

    Default Re: Show Icons in Header of QTreeView

    No one, any idea?
    Do you need further information?

  3. #3
    Join Date
    Apr 2011
    Location
    USA
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Show Icons in Header of QTreeView

    It seems to work for me, but note that you need to return the icon for DecorationRole instead of DisplayRole.

Similar Threads

  1. QMenu does not show icons from QAction
    By eumel1990 in forum Newbie
    Replies: 5
    Last Post: 10th September 2011, 10:57
  2. How to show images from database as icons in QListView
    By LeshaS in forum Qt Programming
    Replies: 2
    Last Post: 21st January 2011, 07:13
  3. QListWidget doesn't show icons
    By franco.amato in forum Qt Programming
    Replies: 8
    Last Post: 16th March 2010, 14:15
  4. how to show richtext and icons in one widget in QT2
    By pencilren in forum Qt Programming
    Replies: 1
    Last Post: 16th May 2007, 10:30
  5. (Qt 4) QTreeview and Icons?
    By pinktroll in forum Qt Programming
    Replies: 4
    Last Post: 17th August 2006, 16:06

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.