Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add decorations (i.e. an icon) to tree view items?
Forum Updated to NodeBB v4.3 + New Features

How to add decorations (i.e. an icon) to tree view items?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #1

    The QTreeView object supplies its own icons for expanding or collapsing the items. This I'd certainly like to keep. But if you take the "Project" view of QtCreator as an example, it should also be possible to add a special icon to each item in addition to the "+/-", or arrows, or whatever else you have (depending on the OS to indicate collapsed/expanded).

    What I would like to do is to add an additional icon for each item which is different, depending whether or not there are child items.

    I set the icon size of the tree view in the constructor of my widget which displays it. Also, in the model I supply to the tree view, I have added code to the model's data() function to return the appropriate icon if it receives a role which is Qt::DecorationRole. The icon is available in the resources compiled into the application.

    What more do I have to do?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      What you see in the QtCreator TreeView is the icon returned by Qt::DecorationRole.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        What you see in the QtCreator TreeView is the icon returned by Qt::DecorationRole.

        R Offline
        R Offline
        Robert Hairgrove
        wrote on last edited by
        #3

        @christian-ehrlicher : Thank you ... I needed to add just one line of code to the function which sets up the data in the tree model ... now it is working properly!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved