Qt开发问答-如何在treewidget的旁边贴上一个图标

关键代码如下:

    QTreeWidgetItem *item = new QTreeWidgetItem;
    item->setIcon(0,QIcon(QString("icon/logo1.png")));
    item->setText(0,QString("top_item1"));
    ui->treeWidget->addTopLevelItem(item);
    QTreeWidgetItem *item_child = new QTreeWidgetItem(item);
    item_child->setIcon(0,QIcon(QString("icon/logo2.png")));
    item_child->setText(0,QString("1_child1"));
    item->addChild(item_child);


    QTreeWidgetItem *item2 = new QTreeWidgetItem;
    item2->setIcon(0,QIcon(QString("icon/logo3.png")));
    item2->setText(0,QString("top_item2"));
    ui->treeWidget->addTopLevelItem(item2);
    QTreeWidgetItem *item_child2 = new QTreeWidgetItem(item2);
    item_child2->setIcon(0,QIcon(QString("icon/logo2.png")));
    item_child2->setText(0,QString("2_child1"));
    item2->addChild(item_child2);

效果图:

Qt开发问答-如何在treewidget的旁边贴上一个图标_第1张图片

 

0积分demo下载:

https://download.csdn.net/download/qq_37385181/12295453

你可能感兴趣的:(Qt开发问答-如何在treewidget的旁边贴上一个图标)