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 the signal when i click the Header in the QTreeWidget, when sortEnable is true.

how can i get the signal when i click the Header in the QTreeWidget, when sortEnable is true.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k Views
  • 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
    #1

    how can i get the signal when i click the Header in the QTreeWidget, when sortEnable is true.
    i want to sort the items all by myself when i click on each column of the Header. not use the sorItems by Qt.
    how can i get the signal?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why not use a custom QSortFilterProxyModel ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        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