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. SetIcon for QTreeWidgetItem
Qt 6.11 is out! See what's new in the release blog

SetIcon for QTreeWidgetItem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.9k 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.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    Here is a code when everything is work:
    @QTreeWidgetItem *item = rootItem->child(i);

    if (item == NULL) {
    rootItem->addChild(new QTreeWidgetItem());
    item = rootItem->child(i);
    }

    item->setData(1,Qt::UserRole, 0);
    item->setIcon(1,QPixmap(":/Images/New.png"));

    item->setText(1,"Some text");@ The text is shown and the icon too. Now code like this will not work: @QTreeWidgetItem * item = new QTreeWidgetItem();

    item->setIcon(1,QPixmap(":/Images/New.png"));
    item->setData(1,Qt::UserRole,1);

    item->setData(1,Qt::DisplayRole,"Some text");
    parent->addChild(item);@
    The text is shown but the icon - not. If i use QApplication::windowIcon() in set icon in second variant of code it works, but ofcourse with application icon, not mine. Maybe it's connected with resource system ?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Anticross
      wrote on last edited by
      #2

      In second code I replace @item->setIcon(1,QPixmap(":/Images/New.png"));@ by @item->setIcon(1,QIcon(":/Images/New.png"));@ and now it's begin to work. But what that was ? All these two piece of code is in on class and currently used. Second piece I add after upgrading to MSVS 2010. But even when I change image in first piece(writed in MSVS 2008) to different from resources it still works.

      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