Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, March 2007
Sorting in Tree Widget


Message 1 in thread

I am having trouble sorting a TreeWidget in Qt 4.2.1, Windows XP. My 
Tree Widget is pretty simple, all TopLevel items, and all numerical data 
(no text). The first column is an integer, and i want to sort by that. 
Everything I've tried gives me ASCII sorting, not numerical.

I have read previous threads about sorting, so this is how I add items 
to the tree:
     int rnr=getRunNr();
     lvitem= new QTreeWidgetItem(moduleRsltList);
     lvitem->setData(0,Qt::DisplayRole,rnr); //  or: setText(0,rnr_str);
     // data[] is an array of double
     for (i=1;i<=ct;i++)
       lvitem->setText(i,QString::number(data[i-1],'f',6));
     moduleRsltList->sortItems(0,Qt::AscendingOrder);

What is wrong here? When I have a list of items with column 0 having 
values of 5,6,7,8,9,10,11,12,13
the sorting gives me 10,11,12,13,5,6,7,8,9 in ascending, backwards of 
that in descending.

What am i doing wrong? Or do i have to subclass the QTreeWidgetItem to 
get this relatively simple behavior?

--
 [ signature omitted ] 

Message 2 in thread

Hi,

> I am having trouble sorting a TreeWidget in Qt 4.2.1, Windows XP. My 
> Tree Widget is pretty simple, all TopLevel items, and all numerical data 
> (no text). The first column is an integer, and i want to sort by that. 
> Everything I've tried gives me ASCII sorting, not numerical.

I think this should help:
	Model/View Programming | Sorting
	http://doc.trolltech.com/4.2/model-view-programming.html#sorting

--
 [ signature omitted ]