Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Sorting QTableView using QSqlRelationalTableModel

    General and Desktop
    3
    5
    3140
    Loading More Posts
    • 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.
    • I
      ihtzudismqa last edited by

      Hello,
      I'm trying to sort a QTableView.
      So far I tried to set
      @
      tableView->setSortingEnabled(true);
      @ but nothing happens.
      Also I tried @ connect(tableView->horizontalHeader(),SIGNAL(sectionClicked(int)), tableView, SLOT(sortByColumn(int))); @
      Any help is greatly appreciated.

      1 Reply Last reply Reply Quote 0
      • D
        DenisKormalev last edited by

        You can use QSortFilterProxyModel to enable sorting that you need. You need to subclass QSortFilterProxyModel and implement couple of methods.

        1 Reply Last reply Reply Quote 0
        • I
          ihtzudismqa last edited by

          Okay, subclassed QSortFilterProxyModel - whats the next step?
          Which methods should I implement? And how should they look like?

          1 Reply Last reply Reply Quote 0
          • D
            DenisKormalev last edited by

            First of all look at Custom Sort/Filter Model example.
            All you need is to reimplement lessThan() method. And of course you need to change all places where you are using indexes of your model (outside of model of course), because you should map them with using QSFPM methods to get your underlying indexes.

            1 Reply Last reply Reply Quote 0
            • A
              andre last edited by

              "This wiki article":https://developer.qt.nokia.com/wiki/QSqlRelationalDelegate_subclass_that_works_with_QSqlRelationalTableModel may also be relevant.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post