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 Update on Monday, May 27th 2025

Sorting QTableView using QSqlRelationalTableModel

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.4k Views
  • 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 4 May 2011, 08:58 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 4 May 2011, 09:20 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 4 May 2011, 09:25 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 4 May 2011, 09:40 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 4 May 2011, 11:55 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

            1/5

            4 May 2011, 08:58

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved