QTreeWidget* treeWidget = new QTreeWidget(); treeWidget->setColumnCount(1); QTreeWidgetItem* item1 = new QTreeWidgetItem(treeWidget); item1->setText(0, "Item 1"); QTreeWidgetItem* subItem1 = new QTreeWidgetItem(item1); subItem1->setText(0, "SubItem 1"); QTreeWidgetItem* subItem2 = new QTreeWidgetItem(item1); subItem2->setText(0, "SubItem 2"); QTreeWidgetItem* item2 = new QTreeWidgetItem(treeWidget); item2->setText(0, "Item 2"); treeWidget->addTopLevelItem(item1); treeWidget->addTopLevelItem(item2);
QTreeWidget* treeWidget = new QTreeWidget(); QTreeWidgetItem* item1 = new QTreeWidgetItem(treeWidget); item1->setText(0, "Item 1"); item1->setIcon(0, QIcon(":/icons/item1_icon.png"));This code creates a tree item named "Item 1" and sets its icon to "item1_icon.png" (located in the application's resources). The `QIcon` class is used to create an icon from the image file. Overall, XTreeWidgetItem is a useful class for creating and customizing a tree view widget in Qt applications.