how can i get sortOrder of QTreeWidget?
General and Desktop
5
Posts
1
Posters
2.4k
Views
1
Watching
-
solved
class MyTreeWidget : public QTreeWidget
{
Q_OBJECTpublic:
MyTreeWidget(QWidget* parent = 0)
: QTreeWidget(parent)
{
// disable built-in sorting
setSortingEnabled(false);// use our own sorting method instead
header()->setSortIndicatorShown(true);
header()->setClickable(true);
connect(header(), SIGNAL(sectionClicked(int)), this, SLOT(customSortByColumn(int)));
customSortByColumn(header()->sortIndicatorSection());
}public slots:
void customSortByColumn(int column)
{
// here you can get the order
Qt::SortOrder order = header()->sortIndicatorOrder();// and sort the items
sortItems(column, order);// to get more control over actual sorting of items,
// reimplement QTreeWidgetItem::operator<()
}
};