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 in QTableWidget with multiple columns - issue
Forum Updated to NodeBB v4.3 + New Features

Sorting in QTableWidget with multiple columns - issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.1k 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
    ShawnZ
    wrote on last edited by
    #1

    I am using qt5.
    I have a qtablewidget with 2 columns.
    Column 1 - is a Qcheckbox where the text is a number
    Column 2 - is a regular QTableWidgetItem

    My issue is sorting column 1 - not sure how to setup
    this up. I am getting conflicting advice from deriving a class
    from QTableWidget in order to control the sort -
    but then I am not sure how to setup the sort for column 1. I need a little more guidance of how sorting works ...

    Or derive a class from QWidgetTableItem for
    the operator<() - but then not I am now sure to know what
    column I sorting.

    Any advice, guidance would be much appreciated.

    Regards

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      Column 1 - is a Qcheckbox

      How do you set it to be a checkbox? there is normally no need to insert a whole widget, you just need to call tableWidgetItem->setFlags(tableWidgetItem->flags() | Qt::ItemIsUserCheckable);
      if you do that you just need to use the Qt::CheckStateRole as sort role

      The normal way to do this however is to split model and view (use QStandardItemModel + QTableView) and insert a QSortFilterProxyModel between the two to manage the sorting

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2

      • Login

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