Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Sort columns of QTreeWidget

    General and Desktop
    3
    4
    5909
    Loading More Posts
    • 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
      Sohoquetaros last edited by

      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 Reply Quote 0
      • F
        Felix last edited by

        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 Reply Quote 0
        • R
          RobotR last edited by

          good!

          1 Reply Last reply Reply Quote 0
          • S
            Sohoquetaros last edited by

            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 Reply Quote 0
            • First post
              Last post