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

  • Thread starter Constantly Distracted
  • Start date
C

Constantly Distracted

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top