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. Sort widgets in QTableWidget?
Forum Updated to NodeBB v4.3 + New Features

Sort widgets in QTableWidget?

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 1.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.
  • S Offline
    S Offline
    sherief
    wrote on last edited by sherief
    #1

    So I have a custom QTableWidget class that I use as a database. My goal is to is to have a push button on top of each column that lets me sort the data in that column.

    I've been able to do it for simple data entries such as name and numerical id using table.sortByColumn, but I have a checkbox in the last column that represents whether or not that person has admin privileges. Is there any way to be able to sort my table based on who has admin privileges?

    The problem is that it's a cellWidget so I'm not sure how to be able to sort in de/ascending order. Ideally, I want to have some kind of backend data where 1 means admin and 0 means user and sort based on that, but again, I'm not sure how to be able to use sortByColumn with that considering it's still a widget at that cell and not a strong or number.

    jsulmJ 1 Reply Last reply
    0
    • S sherief

      So I have a custom QTableWidget class that I use as a database. My goal is to is to have a push button on top of each column that lets me sort the data in that column.

      I've been able to do it for simple data entries such as name and numerical id using table.sortByColumn, but I have a checkbox in the last column that represents whether or not that person has admin privileges. Is there any way to be able to sort my table based on who has admin privileges?

      The problem is that it's a cellWidget so I'm not sure how to be able to sort in de/ascending order. Ideally, I want to have some kind of backend data where 1 means admin and 0 means user and sort based on that, but again, I'm not sure how to be able to use sortByColumn with that considering it's still a widget at that cell and not a strong or number.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sherief You can subclass QTableWidgetItem for your table items and override https://doc.qt.io/qt-5/qtablewidgetitem.html#operator-lt

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      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