QStandardItemModel model; QStandardItem *item = new QStandardItem("Item text"); item->setIcon(QIcon(":/icons/my_icon.png")); model.appendRow(item);
QTreeWidget *treeWidget = new QTreeWidget(); QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, "Item text"); item->setIcon(0, QIcon(":/icons/my_icon.png")); treeWidget->addTopLevelItem(item);In this example, an instance of QTreeWidget is created, and a new item is created with the text "Item text". The setIcon method is then called on the item to set the icon to "my_icon.png" from the resource file. Finally, the item is added to the tree widget using addTopLevelItem method. In conclusion, the setIcon method is provided by the QStandardItem class in the Qt GUI library, which is a C++ cross-platform application framework to develop UI-based applications. The method is used to set the icon for a standard item to display it in a graphical user interface.