PDA

View Full Version : Sorting Tree items based on database properties



jnk5y
12th April 2006, 23:28
Hello all,

Lets suppose I have a database table called people filled with names and addresses. I fill a qTreeWidget by doing



QTreeWidgetItem* peopleNode;
treeWidget->addTopLevelItem( peopleNode );

query.exec( "SELECT first_name FROM people;" );
while( query.next() ) {
QTreeWidgetItem* PeopleList = new QTreeWidgetItem(peopleNode);
PeopleList->setText( 0, query.value(0).toString() );
}

I would like to be able to right click on the peopleNode or items within and have a "sort by" menu which would list all the table columns and then sort the Node by that column.

Can anyone see a way of doing this

wysota
13th April 2006, 11:27
You need a sort-filter proxy model and a context menu for the view.

jnk5y
13th April 2006, 19:30
I'm sorry but I am not familiar with sort-filter proxy model. Could you explain it in further detail?

wysota
13th April 2006, 19:44
Take a look at QSortFilterProxyModel.