Попробуйте.
Я рад, что это именно то, что вам нужно.
Иногда вам может потребоваться указать абсолютный путь для изображения.
if __name__ == '__main__':
# create a empty my_app application
my_app = ''
# test this my_app to create instance
if QApplication.instance() != None:
my_app = QApplication.instance()
else:
my_app = QApplication(sys.argv)
# create a QTreeWidgetItem with tree columns
my_tree= QTreeWidgetItem(["Column A"])
# add date using a for loop
for i in range(6):
list_item_row = QTreeWidgetItem(["Child A-" + str(i)])
list_item_row.addChild(QTreeWidgetItem(['item1']))
my_tree.addChild(list_item_row)
# create my_widget widget
my_widget = QWidget()
my_widget.resize(640, 180)
# create a QTreeWidget named my_tree_widget
my_tree_widget = QTreeWidget(my_widget)
my_tree_widget.setStyleSheet("""QTreeView::branch:open:has-children:!has-siblings{image:url(icons/search.png)}
QTreeView::branch:closed:has-children:!has-siblings{image:url(icons/search.png)}
QTreeView::branch:open:has-children{image:url(icons/search.png)}
QTreeView::branch:closed:has-children{image:url(icons/search.png)}
QTreeView::branch:open:{image:url(icons/search.png)}
QTreeView::branch:closed:{image:url(icons/search.png)}
;""")
my_tree_widget.setWindowIcon(QIcon('icons/search.png'))
# my_tree.setIcon(0,QIcon('icons/search.png'))
# my_tree.setText(0,"testtes")
my_tree_widget.addTopLevelItem(my_tree)
# show the widget
my_widget.show()
# the exit of my_app
sys.exit(my_app.exec_())