1 class LTreeWidget : public QTreeWidget{
2 Q_OBJECT
3 
4 public:
5 
QTreeWidget(parent)6 LTreeWidget(QWidget* parent = 0) : QTreeWidget(parent)
7 {
8 setSortingEnabled(false); // disbale the default built in sorting
9 
10 // our sorting method
11 header()->setSortIndicatorShown(true);
12 header()->setClickable(true);
13 connect(header(), SIGNAL(sectionClicked(int)), this, SLOT(customSortByColumn(int)));
14 customSortByColumn(header()->sortIndicatorSection());
15 }
16 
17 public slots:
customSortByColumn(int column)18 void customSortByColumn(int column)
19 {
20 Qt::SortOrder order = header()->sortIndicatorOrder(); // get the order
21 sortItems(column, order);
22 }
23 };
24