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 columns of QTreeWidget
QtWS25 Last Chance

Sort columns of QTreeWidget

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.3k 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
    Sohoquetaros
    wrote on last edited by
    #1

    Hello,

    I would like give the user the possibility to sort columns in a QTreeWidget.

    What I learned so far:

    • adding items with "myItem->setText( ... )" will sort the column in alphabetical order
    • adding items with "myItem->setData(0, Qt::DisplayRole, QVariant(.. double or QDate ..))" will sort the column according the data (numerial or by date)

    ... but ... (and now comes my problem)
    the data added using "setData( .. )" is represented in an internal way, e.g. double with a dot as decimal delimiter and ugly looking dates.

    I would like to display the data in a localized way (double with a comma, dates in format "dd.MM.yyyy") but still having the possibility to sort them correctly (not alphabetically).

    Is there any solution how to achieve this?

    Thanks a lot for your help !

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Felix
      wrote on last edited by
      #2

      hm i can think of two possibilities for your problem. But I havent tested any of them.

      First one:

      Implement your own QTreewidgetitem subclass, and implement @virtual bool operator< ( const QTreeWidgetItem & other ) const@ there.

      Second one:

      Make own Model and View. then use a QSortFilterProxyModel to sort the view

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RobotR
        wrote on last edited by
        #3

        good!

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sohoquetaros
          wrote on last edited by
          #4

          Thanks, for that good idea.

          Within QT3 I also implemented a subclass of QListViewItem and implemented "virtual int compare( ... )" but I didn't find this within QT4.

          Your first solution is very close to the one I used to have, so I've tried this and it works pretty well !

          Thanks a lot for your help !

          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