Results 1 to 5 of 5

Thread: (Qt 4) QTreeview and Icons?

  1. #1
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default (Qt 4) QTreeview and Icons?

    Hello,

    im using a QTreeView with a QAbstractItemModel.
    Now i like to show a Icon for each Level, like QDirModel does.
    level 1 shows icon1.png
    level 2 shows icon2.png

    How can i do that?

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: (Qt 4) QTreeview and Icons?

    use

    bool QAbstractItemModel::setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole )

    or

    bool QAbstractItemModel::setItemData ( const QModelIndex & index, const QMap<int, QVariant> & roles ) [virtual]

  3. #3
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: (Qt 4) QTreeview and Icons?

    Thank you for the tip! i was just searching for icons, didnt thought of roles.
    But how can i use it? Do you have an short example code?
    Just the thing with showing icons, i dont need to change data in the model, mine is readonly.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: (Qt 4) QTreeview and Icons?

    Return the pixmap in
    Qt Code:
    1. QVariant QAbstractItemModel::data(const QModelIndex& index, int role = Qt::DisplayRole) const
    To copy to clipboard, switch view to plain text mode 
    for role Qt::DecorationRole.

    more or less like this:
    Qt Code:
    1. QVariant MyModel::data(const QModelIndex& index, int role = Qt::DisplayRole) const
    2. {
    3. if (role == Qt::DecorationRole)
    4. {
    5. return QPixmap("some.png");
    6. }
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb Re: (Qt 4) QTreeview and Icons?

    yippih.. thats is!! Thank you so much!!
    You saved me many hours of searching, reading my book and trying!

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 08:52

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.