Results 1 to 3 of 3

Thread: QTableView sorting

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    N.B. Canada
    Posts
    47
    Thanked 8 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView sorting

    What's the most proper way of sorting a QTableView? QSortFilterProxyModel doesn't seem to work on QTableViews. At least I can't get it to work. For example if I take the sorting treeview example, and just change it so there is a QTableView, it doesn't work:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. QFile file(":/default.txt");
    6. file.open(QIODevice::ReadOnly);
    7. TreeModel model(file.readAll());
    8. file.close();
    9.  
    10. QSortFilterProxyModel sortingModel;
    11. sortingModel.setSourceModel(&model);
    12.  
    13. QTableView sortedView;
    14. sortedView.setModel(&sortingModel);
    15. sortedView.setWindowTitle("Sorted Data");
    16. sortedView.setSelectionBehavior(QAbstractItemView::SelectRows);
    17. sortedView.horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
    18. sortedView.horizontalHeader()->setSortIndicatorShown(true);
    19. sortedView.horizontalHeader()->setClickable(true);
    20. sortedView.verticalHeader()->setVisible(false);
    21. sortedView.show();
    22.  
    23. return app.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

    I would like to be able to sort the rows based on the column data in the clicked column. Qt 4.1. I don't need sample source code, just description of what to do, what things to connect, etc... Any advice is much appreciated.

    Bojan
    Last edited by Bojan; 9th March 2006 at 03:05.
    The march of progress:
    C:
    printf("%10.2f", x);
    C++:
    cout << setw(10) << setprecision(2) << showpoint << x;
    Java:
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);

Similar Threads

  1. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  2. Refresh QTableView after sorting
    By araglin in forum Newbie
    Replies: 4
    Last Post: 18th December 2008, 22:13
  3. QTableView sorting problem
    By noktus in forum Newbie
    Replies: 11
    Last Post: 23rd April 2008, 10:20
  4. QSqlTableModel and QTableView and sorting
    By JeanC in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2008, 13:22
  5. Sorting QTableView
    By Jimmy2775 in forum Qt Programming
    Replies: 7
    Last Post: 9th February 2006, 16:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.