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. Sorting the row based on the value of certain columns of QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Sorting the row based on the value of certain columns of QTableWidget

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 2 Posters 1.6k 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.
  • W Offline
    W Offline
    Willkroken
    wrote on last edited by
    #1

    I am having trouble in PyQt5 trying to sort my rows based on a change in value of certain columns in my table. I need to check a column and then if that is higher than the corresponding column in the other rows the rows need to rearrange themselves from highest to lowest.

    I am using an array to print my values in the QTableWidget that looks something like this:
    self.tableData = [
    ['FC Inter', 0, 0, 0, 0, 0, 0, 0, 0],
    ['AC Milan', 0, 0, 0, 0, 0, 0, 0, 0],
    ['AS Roma', 0, 0, 0, 0, 0, 0, 0, 0]
    ]
    The zeros being variables in my code. I need to check 3 different columns to check what order the rows should be arranged in. Please help

    JonBJ 1 Reply Last reply
    0
    • W Willkroken

      I am having trouble in PyQt5 trying to sort my rows based on a change in value of certain columns in my table. I need to check a column and then if that is higher than the corresponding column in the other rows the rows need to rearrange themselves from highest to lowest.

      I am using an array to print my values in the QTableWidget that looks something like this:
      self.tableData = [
      ['FC Inter', 0, 0, 0, 0, 0, 0, 0, 0],
      ['AC Milan', 0, 0, 0, 0, 0, 0, 0, 0],
      ['AS Roma', 0, 0, 0, 0, 0, 0, 0, 0]
      ]
      The zeros being variables in my code. I need to check 3 different columns to check what order the rows should be arranged in. Please help

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Willkroken

      I need to check 3 different columns to check what order the rows should be arranged in

      If you stick with a QTableWidget, you have to sort your table by your criteria before you put the rows into the table, so go ahead and do so.

      Or it seems to me if the answer at https://stackoverflow.com/a/18652060/489865 using

      You can try to subclass the QTableWidgetItem and reimplement operator<() of it.

      works that is possible, but I don't know how you override an operator from Python.

      If you move to a QTableView and have your own model, you can interpose a QSortFilterProxyModel and override lessThan() to do your 3 column comparison.

      1 Reply Last reply
      1

      • Login

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