Nominate our 2022 Qt Champions!

how can i get sortOrder of QTreeWidget?

  • how can i get sortOrder of QTreeWidget?
    is it depends on the sortColumn?
    thank you very much!

  • This post is deleted!

  • if there is no way to get the sortOrder directly,
    can i add a memeber which record the order manually...but how can i set this new member when i click on the Header to sort the items?

  • i saw a API sortOrder, but it's private......

  • solved
    class MyTreeWidget : public QTreeWidget

    MyTreeWidget(QWidget* parent = 0)
    : QTreeWidget(parent)
    // disable built-in sorting

    // use our own sorting method instead
    connect(header(), SIGNAL(sectionClicked(int)), this, SLOT(customSortByColumn(int)));

    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<()

Log in to reply