PDA

View Full Version : Tree widget sorting



ganeshshenoy
11th February 2008, 05:48
I want to sort the tree widget based on the user data not the text displayed in the tree widget. How can i do this? MFC has the function SetItemData for the controls where we can store the user data in the nodes. How can i achieve this in QT. For example I want to display the names but it has to be sorted on age corresponding to name (which is user data).

jpn
11th February 2008, 07:55
Hi, you can reimplement QTreeWidgetItem::operator<() (http://doc.trolltech.com/latest/qtreewidgetitem.html#operator-lt) to your like.

ganeshshenoy
11th February 2008, 13:02
How can i store the user data in QTreewidgetitem?

jpn
11th February 2008, 13:06
See QTreeWidgetItem::setData():

item->setData(column, Qt::UserRole, data);