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. Sort QTableWidget by two colums
Forum Updated to NodeBB v4.3 + New Features

Sort QTableWidget by two colums

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 357 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.
  • A Offline
    A Offline
    AndreaCT
    wrote on last edited by
    #1

    Hi! Is possible to sort a QTableWidget by two columns?

    I use sortItems(column, Qt::DescendingOrder) to sort by single column, but I would also sort the equal values by another columns.

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I am not aware of that possibility for QTableWidget.
      However you can change that with a QTableView, QSortFilterProxyModel, QStandardItemModel and do that with a custom QSortFilterProxyModel.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        I am not aware of that possibility for QTableWidget.
        However you can change that with a QTableView, QSortFilterProxyModel, QStandardItemModel and do that with a custom QSortFilterProxyModel.

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

        @SGaist said in Sort QTableWidget by two colums:

        I am not aware of that possibility for QTableWidget.

        QTableWidgetItem has [virtual]bool QTableWidgetItem::operator<(const QTableWidgetItem &other) const, https://doc.qt.io/qt-5/qtablewidgetitem.html#operator-lt. If QTableWidget calls this method for sorting items (I don't know whether it does, but hopefully that's why it's there), if @AndreaCT subclasses QTableWidgetItem for the items he adds into the table, he can override that and see if works? At least well enough to deal with other columns when sorted column values are equal?

        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