Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    TreeView and an Icon

    General and Desktop
    3
    4
    684
    Loading More Posts
    • 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.
    • ?
      A Former User last edited by

      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 Reply Quote 0
      • p3c0
        p3c0 Moderators last edited by

        @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 Reply Quote 2
        • ?
          A Former User last edited by

          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 Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by

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

            1 Reply Last reply Reply Quote 2
            • First post
              Last post