Results 1 to 3 of 3

Thread: QTreeview DecorationRole icon depending on expanded

  1. #1
    Join Date
    Mar 2011
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeview DecorationRole icon depending on expanded

    Hi,

    In a QTreeView I would like to show a DecorationRole icon depending on the expanded value, e.g. open folder icon for expanded, closed folder for not expanded.

    Thanks!

    Thomas

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTreeview DecorationRole icon depending on expanded

    You could use the QTreeView's signal expanded(const QModelIndex & index), and connect it to a slot of some object which can access the model->setData(OpenIcon, Qt::DecorationRole), and similarly use the QTreeView's signal collapsed(const QModelIndex & index), and connect it to a slot of some object which can access the model->setData(CloseIcon, Qt::DecorationRole).

    Note that, when you have multiple views connected to same model, expanding the item in a view will not expand the items in other view, but their icon will change, and will appear that the icon and actual state (expanded/collapsed) do not match.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Mar 2011
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeview DecorationRole icon depending on expanded

    Thank you.

    Does it make sense to make a feature request for such things? If yes, how to make this?

Similar Threads

  1. Replies: 1
    Last Post: 20th August 2013, 11:14
  2. Replies: 5
    Last Post: 13th November 2011, 21:49
  3. Display QTreeView expanded in QDialog
    By LynneV in forum Qt Programming
    Replies: 3
    Last Post: 21st December 2010, 21:32
  4. Replies: 6
    Last Post: 3rd November 2010, 16:21
  5. QTreeView restore Expanded node after reload model
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2008, 18:42

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.