PDA

View Full Version : [QT4] QTreeView, QAbstractItemModel and sorting



KShots
21st March 2006, 17:59
Hello all...

I'd thought I'd attempt to implement some sorting algorithms for my tree... and noticed a virtual function in QAbstractItemModel that handles sorting (which does nothing if not re-implemented). I went ahead and re-implemented that function... and found that it doesn't seem to get activated when I click on a heading.

I'm not positive that Qt by default does sorting when you click on a heading, so my first question is how to make that happen.

If it does, what else do I need to look at to enable sorting?

Thanks

jpn
21st March 2006, 18:09
At least the header needs to set clickable..


view->header()->setSortIndicatorShown(true); // optional
view->header()->setClickable(true);

KShots
24th March 2006, 19:47
Thanks, that plus emitting a dataChanged signal in my model was all I needed. It works fine now :)

Puzzled note: Why didn't I get an e-mail that someone responded to this msg? Odd...

EDIT: Now that I think of it, the dataChanged() signal has two variables contained within it: QModelIndex & topLeft and QModelIndex & bottomRight. This makes sense for a table model, and can easily make sense for a list model... but what the heck is the bottom right of a tree? :confused:

Would that be the last item under the root node, or the last item of the deepest node?

KShots
24th March 2006, 21:16
One last question:

How can I disable the sort indicator for a specific column? There are some columns in my model that sorting would make no sense on. My sort function does nothing on them, but the sort indicator shows up and flips around when I click on them.

I would have hoped for a view->header()->setClickable(int logicalIndex, bool clickable) type function, but I don't see one.