How do I sort items in a tableview without a column being selected?

Constantly Distracted Wayne.Oosthuizen at gmail.com
Sat Jun 14 15:34:43 CEST 2008


I have this TableView, which is sorted by column when the user clicks
on the header. The problem is though, that all the items are selected
and nothing gets sorted. But if the window loses focus everything's
get's sorted.

Basically I have list of tags say,
[{"artist":"Artist1","title":Title1"} , {"artist":"Artist2" , "title":
"Title2"}] etc. Where each tag is listed in a column. Then I sort them
and reset. Here's the code:

    def sort(self,column,order=Qt.DescendingOrder):
        tag=self.headerdata.text
        newdic={}
        li=[]
        i=0
        for z in self.taginfo: #taginfo has all the tags
            if not newdic.has_key(z[tag]):
                newdic[z[tag]]=z
                li.append(z[tag])
            else:
                newdic[z[tag] + str(i)]=z
                li.append(z[tag] + str(i))
                i+=1
        li.sort()
        self.taginfo=[newdic[z] for z in li]
        self.reset()

Any ideas?



More information about the Python-list mailing list