Results 1 to 4 of 4

Thread: setIcon not working in QTreeWidgetItem?

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default setIcon not working in QTreeWidgetItem?

    Hai,


    Qt Code:
    1. for(int i=0; i<3; i++)
    2. {
    3. QStringList strings;
    4. strings << QString("Wit Name");
    5. QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
    6. ui->firstTreeWidget->addTopLevelItem(parent);
    7. parent ->setIcon(0,QIcon(QString::fromUtf8(":/images/heart.ico")));
    8. parent->addChild(child);
    9. ui->firstTreeWidget->setItemWidget(child, 0, new QLineEdit(ui->firstTreeWidget));
    10. }
    To copy to clipboard, switch view to plain text mode 


    Icon is not setting . Is there any problem in the code

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setIcon not working in QTreeWidgetItem?

    If you get *.ico file from resource, this file will be for example like this:
    123.jpg
    Use code QIcon(":images/heart.ico"), not QIcon(":/images/heart.ico")
    Or try load *.png file

  3. #3
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setIcon not working in QTreeWidgetItem?

    Thanx Jonny174 . but i dont still get the image . i want it next to the " Witname". what can i do in this?

  4. #4
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setIcon not working in QTreeWidgetItem?

    arent->setIcon( 0, QPixmap::fromImage( QImage("file.ico") ) );

  5. The following user says thank you to Jonny174 for this useful post:

    vinayaka (2nd March 2012)

Similar Threads

  1. SetIcon ON for pushbutton does not work
    By tonnot in forum Newbie
    Replies: 6
    Last Post: 14th September 2011, 13:24
  2. Replies: 3
    Last Post: 24th July 2011, 23:13
  3. QAbstractButton::setIcon | Icon posiition
    By ouekah in forum Newbie
    Replies: 2
    Last Post: 11th May 2010, 00:56
  4. QTreeWidget Crashing while setText,setFont,setIcon
    By santosh.kumar in forum Qt Programming
    Replies: 3
    Last Post: 19th February 2008, 12:36
  5. setIcon() - different QIcon states?
    By AaronMK in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2008, 04:10

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.