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.
    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?


  • Lifetime Qt Champion

    Hi,

    Why not use a custom QSortFilterProxyModel ?



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.