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. Sorting QTreeWidget after adding a row

Sorting QTreeWidget after adding a row

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.8k 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.
  • X Offline
    X Offline
    xwhatsit
    wrote on last edited by
    #1

    Hello,

    I'm programmatically sorting a QTreeWidget using sortItems(int column, Qt::SortOrder order). It works, of course. However, if I do it right after adding some items to the tree, the sort won't take effect.

    I've even tried calling sortItems from a one-shot QTimer. This works a little bit better, but still fails 50% of the time. Clearly something needs to be "updated" or validated in the QTreeWidget before the sort will work.

    Is there a way to force the QTreeWidget to update so I can call sortItems immediately?

    Many thanks.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      diegosarmentero
      wrote on last edited by
      #2

      If you are inside a class that extends QTreeWidget you can call:
      updateGeometries()
      To force update...
      But maybe, what you really need is to connect the signal from QTreeWidget:
      itemChanged(...)
      Or something like that, with a slot in your code (where you apply the sorting), so you are going to be sure that the method is going to be called after the proper update of that widget...

      Diego Sarmentero
      Blog: http://diegosarmentero.com.ar
      Twitter: http://twitter.com/diegosarmentero

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xwhatsit
        wrote on last edited by
        #3

        updateGeometry() doesn't work. It appears to be more to do with child widgets rather than items in the view.

        The itemChanged() signal however appears to work very nicely! It also means I can connect the signal once and then forget about manually calling sortItems() every time I need to sort.

        Thanks very much!

        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