如何将箭头移动到 qtreewidget 中的下一列
How to move arrows to the next column in qtreewidget
在 pyqt5 中,使用 qtreewidget,我试图移动下一个 header 下的箭头。这可能吗?我想在第一列添加缩略图,在第二列添加箭头。
这就是我目前的情况。
这是我移动所有内容时得到的结果,箭头位于 header 0
下方
模拟我想要的东西
我尝试过的简化示例。
import sys
from PyQt5.QtWidgets import (QVBoxLayout, QDialog, QTreeWidget, QApplication, QTreeWidgetItem)
class QuickExample(QDialog):
def __init__(self, parent=None):
super(QuickExample, self).__init__(parent)
layout = QVBoxLayout()
tree = QTreeWidget()
tree.setHeaderLabels(["0", "1"])
parent = QTreeWidgetItem()
parent.setText(1, "parent")
child = QTreeWidgetItem(parent)
child.setText(1, "child")
tree.addTopLevelItem(parent)
layout.addWidget(tree)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
example = QuickExample()
example.show()
sys.exit(app.exec_())
我最终设置了第一列中的项目并将它们与第二列交换。例如
import sys
from PyQt5.QtWidgets import (QVBoxLayout, QDialog, QTreeWidget,
QApplication, QTreeWidgetItem)
class QuickExample(QDialog):
def __init__(self, parent=None):
super(QuickExample, self).__init__(parent)
layout = QVBoxLayout()
tree = QTreeWidget()
tree.setHeaderLabels(["Name", "Thumbnail"])
# swapping the first with the second
tree.header().swapSections(1, 0)
parent = QTreeWidgetItem()
parent.setText(0, "parent")
child = QTreeWidgetItem(parent)
child.setText(0, "child")
tree.addTopLevelItem(parent)
layout.addWidget(tree)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
example = QuickExample()
example.show()
sys.exit(app.exec_())
现在我可以随意向新的第一列添加缩略图了。
在 pyqt5 中,使用 qtreewidget,我试图移动下一个 header 下的箭头。这可能吗?我想在第一列添加缩略图,在第二列添加箭头。
这就是我目前的情况。
这是我移动所有内容时得到的结果,箭头位于 header 0
下方模拟我想要的东西
我尝试过的简化示例。
import sys
from PyQt5.QtWidgets import (QVBoxLayout, QDialog, QTreeWidget, QApplication, QTreeWidgetItem)
class QuickExample(QDialog):
def __init__(self, parent=None):
super(QuickExample, self).__init__(parent)
layout = QVBoxLayout()
tree = QTreeWidget()
tree.setHeaderLabels(["0", "1"])
parent = QTreeWidgetItem()
parent.setText(1, "parent")
child = QTreeWidgetItem(parent)
child.setText(1, "child")
tree.addTopLevelItem(parent)
layout.addWidget(tree)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
example = QuickExample()
example.show()
sys.exit(app.exec_())
我最终设置了第一列中的项目并将它们与第二列交换。例如
import sys
from PyQt5.QtWidgets import (QVBoxLayout, QDialog, QTreeWidget,
QApplication, QTreeWidgetItem)
class QuickExample(QDialog):
def __init__(self, parent=None):
super(QuickExample, self).__init__(parent)
layout = QVBoxLayout()
tree = QTreeWidget()
tree.setHeaderLabels(["Name", "Thumbnail"])
# swapping the first with the second
tree.header().swapSections(1, 0)
parent = QTreeWidgetItem()
parent.setText(0, "parent")
child = QTreeWidgetItem(parent)
child.setText(0, "child")
tree.addTopLevelItem(parent)
layout.addWidget(tree)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
example = QuickExample()
example.show()
sys.exit(app.exec_())
现在我可以随意向新的第一列添加缩略图了。