Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how can i get sortOrder of QTreeWidget?
Forum Updated to NodeBB v4.3 + New Features

how can i get sortOrder of QTreeWidget?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 1 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by opengpu2
    #1

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

    1 Reply Last reply
    0
    • O Offline
      O Offline
      opengpu2
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • O Offline
          O Offline
          opengpu2
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • O Offline
            O Offline
            opengpu2
            wrote on last edited by
            #5

            solved
            class MyTreeWidget : public QTreeWidget
            {
            Q_OBJECT

            public:
            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<()
            }
            };

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved