View Full Version : [pyqt]Overriding operator< in QTreeWidgetItem

8th May 2011, 15:10

Could you tell me how should I implement the override of operator< in QTreeWidgetItem?
I am asking because I can't find source code of original QTreeWidgetItem implementation in Python and I just don't know how it looks like.

21st May 2011, 15:08
i have the same question. did you solve it :)?

5th September 2011, 22:39
I receive private messages with question whether I found the answer to my question. Unfortunately, I still don't know how to override operator. I even posted exactly the same question on PyQT mailling list: http://article.gmane.org/gmane.comp.python.pyqt-pykde/22490/match=overriding+operator

Again, no response I got...

I promise to post solution as soon as I find the answer :).

Please don't hesitate to post your own solution in this thread if you have it ;)...

19th September 2011, 20:25
hi, I'm sorry that I forgot to post solution i have found some time later:

class myTreeWidgetItem( QTreeWidgetItem ):
def __init__(self, parent=None):
QTreeWidgetItem.__init__(self, parent)

def __lt__(self, otherItem):
column = self.treeWidget().sortColumn()

if column == 0 or column == 6 or column == 7 or column == 8:
return float( self.text(column) ) < float( otherItem.text(column) )
return self.text(column) < otherItem.text(column)

or http://stackoverflow.com/questions/363200/is-it-possible-to-sort-numbers-in-a-qtreewidget-column