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. TreeView and an Icon
Qt 6.11 is out! See what's new in the release blog

TreeView and an Icon

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.7k Views 2 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I have a TreeView made with QAbstractItemModel. Now i want to add an Icon to the left of the Text. I found QStyledItemDelegate for that, but at the moment i dont know how to do that. Its very hard for a Beginner like me to understand that MV Framework in that way. I only want to show an Icon on the leftside of each TreeItem.

    Is it only possible to do that with the paint method in the QStyledItemDelegate? If yes, how?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @Fuel
      Is it only possible to do that with the paint method in the QStyledItemDelegate? If yes, how?

      if you have use QStandardItem you can use setIcon to set the icon but then then the actual drawing is done using drawPixmap . Something like this in paint:

      QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
      QPixmap pixmap = icon.pixmap(QSize(24, 24));
      painter->drawPixmap(rect(), pixmap);
      

      157

      1 Reply Last reply
      2
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thats the Problem. I used an own Class for a TreeItem. Do i need to implement an Icon in to this Item Class?

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          If you inherited QStandardItem for your class, it should still be the same?

          1 Reply Last reply
          2

          • Login

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