Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-74114

Overhaul the sorting of QTreeWidget resp. QAbstractItemModel

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 5.12.0, 5.13.0 Alpha 1
    • Core: Item Models
    • None
    • Windows

    Description

      Hi all,

      currently I've searched for a method to turn on the sorting by column of QTreeWidget / QTableWidget with the behaviour to sort the items ONLY when the user clicks a column section.

      For god's sake this is really a pain in the ass.

      The method setSortingEnabled will immediately sort the first column, who ever was thinking this was a good idea, was out of his senses.

      Currently you need to call setSectionsClickable(true) and catch sortIndicatorChanged where within you call sortByColumn on your own. This can't be combined with setSortIndicatorShown.

      My suggestion for a much better and useful behaviour:

      1. setSortingEnabled will not immediately sort the first column. Sorting will only take place if the user forces it through a click in the header section or programmatically through sortByColumn.
      2. Sorting needs to have three states instead of two state: None, AscendingOrder, DescendingOrder
        This have to be used to restore the original insert order, so that the user can turn of the Ascending/Descending order, where the sortIndicator will be hidden.
      3. It would be useful to define sections which shouldn't be sorted. Something like:
        header()->disableSortingByColumn(int logicIndex, bool disabled)

      These three changes will give the models/widgets a wide range of possibilities to configure them to your own needs. Such as only sorting through user interactions, disable sorting for columns/rows and restoring the original insert order through the user with indicators enabled.

      I know that a proxy model is able to fulfill some of these requirements, but not everyone wants to write own models for some simple structured data / widgets.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            dfaure_kdab David Faure
            lachrymology Mike
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes