diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-10-20 13:19:43 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-11-30 18:16:21 +0200 |
commit | d982fdfca43165b31db7f7c3602b93f7197aeee8 (patch) | |
tree | 41ae57ce777d883abd909a092e91317341363440 /src/widgets/itemviews/qheaderview.h | |
parent | 3cacf1d1bd97c631465bb98edf6d00bff5bd5099 (diff) |
QHeaderView: allow un-sorting of models
If one clicks on a QHeaderView's section, the header view will
sort the view by the respective column/row. By clicking multiple
times, one is able to toggle the sorting between ascending
and descending. Something that is NOT possible to do however is to
un-sort the view -- that is, to restore the model's original
sorting. This must be done via code, by asking the header or the
view to sort by section -1.
This commit adds new property to QHeaderView to make it possible
to unsort models. Basically, the sort indicator becomes a tri-state:
sort ascending, sort descending, unsort (sort by column -1).
[ChangeLog][QtWidgets][QHeaderView] Added the sortIndicatorClearable
property. Setting this property allows the user to clear the sort
indicator on a section, resetting the model to its default ordering.
Change-Id: Ibf4e280b2086b75ccd64d619ea4d70816dc3529f
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/itemviews/qheaderview.h')
-rw-r--r-- | src/widgets/itemviews/qheaderview.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qheaderview.h b/src/widgets/itemviews/qheaderview.h index a836f4a50a..baad5c024b 100644 --- a/src/widgets/itemviews/qheaderview.h +++ b/src/widgets/itemviews/qheaderview.h @@ -62,6 +62,7 @@ class Q_WIDGETS_EXPORT QHeaderView : public QAbstractItemView Q_PROPERTY(int minimumSectionSize READ minimumSectionSize WRITE setMinimumSectionSize) Q_PROPERTY(int maximumSectionSize READ maximumSectionSize WRITE setMaximumSectionSize) Q_PROPERTY(Qt::Alignment defaultAlignment READ defaultAlignment WRITE setDefaultAlignment) + Q_PROPERTY(bool sortIndicatorClearable READ isSortIndicatorClearable WRITE setSortIndicatorClearable NOTIFY sortIndicatorClearableChanged) public: @@ -140,6 +141,9 @@ public: int sortIndicatorSection() const; Qt::SortOrder sortIndicatorOrder() const; + void setSortIndicatorClearable(bool clearable); + bool isSortIndicatorClearable() const; + bool stretchLastSection() const; void setStretchLastSection(bool stretch); @@ -186,6 +190,7 @@ Q_SIGNALS: void sectionHandleDoubleClicked(int logicalIndex); void geometriesChanged(); void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order); + void sortIndicatorClearableChanged(bool clearable); protected Q_SLOTS: void updateSection(int logicalIndex); |