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. QTreeWidget multiple sorts
Forum Updated to NodeBB v4.3 + New Features

QTreeWidget multiple sorts

Scheduled Pinned Locked Moved General and Desktop
qtreewidgetsort
2 Posts 1 Posters 1.5k 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.
  • M Offline
    M Offline
    Mailchuck
    wrote on 2 Oct 2015, 20:47 last edited by
    #1

    I'm using QTreeWidget with custom sort based on what I found through searching:

    • setSortingEnabled,
    • the elements of QTreeWidget are a new class that is a child of QTreeWidgetItem and has its own definition of the method __lt__ (in python, from what I understand in C++ it would be the < method).

    It seems to work. However, what I want to do is for the sorting to behave differently depending on whether the sort order of QTreeWidget is normal or reverse. I don't want it to simply reverse the order.

    When you set setSortingEnabled to true, the widget title will become clickable and there is an arrow pointing down or up depending on whether the sort order is ascending or descending. What I want to do is for my class to query the QTreeWidget and find out what the direction is, or something similar that will help me. I was unable to find how to do this. Is there a method or an attribute for this?

    I use PyQt4 if that is important.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mailchuck
      wrote on 3 Oct 2015, 10:01 last edited by
      #2

      I figured it out, that information is the header of the QTreeWidget. So, the code to extract this value from within a QTreeWidgetItem is:

      self.treeWidget().header().sortIndicatorOrder()
      

      and this you can check for being equal to Qt.DescendingOrder (or Qt.AscendingOrder if you prefer).

      1 Reply Last reply
      0

      2/2

      3 Oct 2015, 10:01

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved