pyqt5 我想删除 QTreeWidget 中的箭头图标

pyqt5 I want to remove arrow icon in QTreeWidget

这是我的代码 我想删除箭头图标,我只想看到用于展开节点的搜索图标。 有什么办法吗?

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.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_())

请尝试一下。

很高兴这是你想要的。

有时,您可能需要为图片设置绝对路径。

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_())