PDA

View Full Version : setIcon not working in QTreeWidgetItem?



vinayaka
2nd March 2012, 06:38
Hai,





for(int i=0; i<3; i++)
{
QStringList strings;
strings << QString("Wit Name");
QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
ui->firstTreeWidget->addTopLevelItem(parent);
parent ->setIcon(0,QIcon(QString::fromUtf8(":/images/heart.ico")));
QTreeWidgetItem *child = new QTreeWidgetItem;
parent->addChild(child);
ui->firstTreeWidget->setItemWidget(child, 0, new QLineEdit(ui->firstTreeWidget));
}



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

Jonny174
2nd March 2012, 10:51
If you get *.ico file from resource, this file will be for example like this:
7460
Use code QIcon(":images/heart.ico"), not QIcon(":/images/heart.ico")
Or try load *.png file

vinayaka
2nd March 2012, 11:16
Thanx Jonny174 . but i dont still get the image . i want it next to the " Witname". what can i do in this?

Jonny174
2nd March 2012, 11:41
arent->setIcon( 0, QPixmap::fromImage( QImage("file.ico") ) );