我有一个QTableWidget,第一列填充了可检查项,所以我需要重载这些项才能对它们进行排序:
class CheckBoxItem(QtGui.QTableWidgetItem):
def __init__(self, doSelect):
QtGui.QTableWidgetItem.__init__(self, doSelect)
self.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
if doSelect:
self.setCheckState(QtCore.Qt.Checked)
else:
self.setCheckState(QtCore.Qt.Unchecked)
def __lt__(self, other):
return self.checkState() < other.checkState()
当我单击该列的标题时,它的工作和预期一样:行被排序-首先有选中的行,然后没有被选中。在
问题当我不点击任何列的标题然后使用tableWidget.setSortingEnabled(1)
时,如果我有~15行随机混合一些行,而不是对它们进行排序,那么{setSortingEnabled(1)
之前,我已经检查/取消选中了一些项目,但我不希望__lt__
对它们进行比较,因为我没有单击该列的标题对它们进行排序。在
我有6列(0-5),如果我没有单击其中任何一列的标题进行排序,tableWidget.horizontalHeader().sortIndicatorSection()
返回{
那么,为什么要调用__lt__
?覆盖时是否遗漏了某些内容?
我认为这可以解决问题(只在单击该列的标题时比较项),但是如何将sortIndicatorSection
传递给__lt__
?在
请帮帮我,我是个笨蛋。在
我解决了。原来^{{cd1>}返回“6”(我不知道为什么),但是排序的行为就像是0,因为它在文档中被写入:
这可能是因为我有tableWidget而不是tableView。
所以我发现了:
^{pr2}$它适用于QTableWidget。我已经在填充表^{cd2>}之前放了这行,这解决了我的问题。
相关问题 更多 >
编程相关推荐