Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Custon sorting behaviour when clicking on a Qtableview header
Forum Updated to NodeBB v4.3 + New Features

Custon sorting behaviour when clicking on a Qtableview header

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 462 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.
  • H Offline
    H Offline
    hachbani
    wrote on 28 Jan 2021, 09:37 last edited by
    #1

    Hello,

    I want to implement the following behaviour:

    • the first click on a header sort the table in ascending order
    • a second click sort on same header sort it in descending order
    • a third click goes back to my default sorting (which I already implemented in lessThan() method in my Proxy method)

    I have a Qtableview, set to a QSortFilterProxyModel (subclassed) and a QAbstractTableModel (subclassed). Working on Pyside2

    I would like to implement this in my ProxyModel

    any hints on how to do that, I don't know how to get started in this.

    thanks

    J 1 Reply Last reply 28 Jan 2021, 09:57
    0
    • H hachbani
      28 Jan 2021, 09:37

      Hello,

      I want to implement the following behaviour:

      • the first click on a header sort the table in ascending order
      • a second click sort on same header sort it in descending order
      • a third click goes back to my default sorting (which I already implemented in lessThan() method in my Proxy method)

      I have a Qtableview, set to a QSortFilterProxyModel (subclassed) and a QAbstractTableModel (subclassed). Working on Pyside2

      I would like to implement this in my ProxyModel

      any hints on how to do that, I don't know how to get started in this.

      thanks

      J Online
      J Online
      JonB
      wrote on 28 Jan 2021, 09:57 last edited by JonB
      #2

      @hachbani
      Well you sound like you are almost there already! You have picked the right hierarchy.

      Since you have three states, at some level you need to note that so you know where you are, and move through them as desired from clicking. You probably want this "state flag" stored in the sub-classed QSortFilterProxyModel, so that knows what it should do about which sorting to apply. Then the UI deals with the clicks and tells the proxy model to move through the 3 states.

      1 Reply Last reply
      0

      1/2

      28 Jan 2021, 09:37

      • Login

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