QTableView | catch sort signal and sort



  • I want to reimplement the sorting method for my QTableView (so I can restore a selection). No matter how I try to connect it, I click the TableView header and my method is not called. (there is no output "sortTableView")

    This is how I'm trying to connect the signal:

    @connect(tableView->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(sortTableView(int)));@

    This is how my method looks like:

    @
    void myWindow::sortTableView(int column)
    {
    cout << "sortTableView" << endl;

    //remember the ids of the selected rows
    ...

    bool ascending = (tableView->horizontalHeader()->sortIndicatorSection() == column && tableView->horizontalHeader()->sortIndicatorOrder() == Qt::DescendingOrder);
    Qt::SortOrder order = ascending ? Qt::AscendingOrder : Qt::DescendingOrder;

    tableView->horizontalHeader()->setSortIndicator(column, order);
    tableView->sortByColumn(column, order);

    //restore the selection using the saved ids
    ...
    }
    @

    According to the internet, that should work..
    What am I missing? Any help appreciated!


Log in to reply
 

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