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. Sorting QTableView using QSqlRelationalTableModel
Forum Updated to NodeBB v4.3 + New Features

Sorting QTableView using QSqlRelationalTableModel

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.5k Views 1 Watching
  • 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 Offline
    I Offline
    ihtzudismqa
    wrote on last edited by
    #1

    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
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ihtzudismqa
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          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
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

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

            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