Results 1 to 3 of 3

Thread: TreeWidget child icon

  1. #1
    Join Date
    Oct 2009
    Location
    Rio de Janeiro - Brazil
    Posts
    19
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default TreeWidget child icon

    Hi,

    How can I put a icon in a child item on TreeWidget?

    In my way, I can use icon only in root item, but I need to show a icon for each child.

    My code:
    Qt Code:
    1. QTreeWidgetItem *devices = new QTreeWidgetItem(ui->treeViewMap);
    2. devices->setText(0, tr("Devices"));
    3. devices->setIcon(0, QIcon(":/pixmaps/computer1.png")); // <- it's ok, the icon is showed!
    4. QList<QTreeWidgetItem *> device_items;
    5. query = mDB.setQuery("SELECT * FROM element_type");
    6. while(query.next())
    7. {
    8. device_items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(query.value(1).toString()))));
    9.  
    10. // device_items.setIcon ?????
    11. }
    12. devices->insertChildren(0, device_items);
    To copy to clipboard, switch view to plain text mode 

    Some idea?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: TreeWidget child icon

    Simple create a temp pointer!
    Qt Code:
    1. while(query.next())
    2. {
    3. QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(query.value(1).toString())));
    4. item->setIcon(/*...*/);
    5. device_items.append(item);
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    junix (1st June 2010)

  4. #3
    Join Date
    Oct 2009
    Location
    Rio de Janeiro - Brazil
    Posts
    19
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: TreeWidget child icon

    Hi Lykurg,

    It's works!

    Thank you, man.

    BR,

    Junix

Similar Threads

  1. Replies: 2
    Last Post: 18th May 2010, 22:44
  2. TreeWidget + Icon, does not scale
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 8th October 2009, 09:07
  3. Couple of questions: main window icon + toolbar icon
    By bpackard in forum Qt Programming
    Replies: 0
    Last Post: 20th March 2008, 19:03
  4. MDI child form icon
    By tebessum in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2008, 09:33
  5. Replies: 2
    Last Post: 14th November 2006, 11:22

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.