Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Treeview / QSortFilterProxyModel rendering problem..
Forum Updated to NodeBB v4.3 + New Features

Treeview / QSortFilterProxyModel rendering problem..

Scheduled Pinned Locked Moved Unsolved Language Bindings
6 Posts 3 Posters 2.0k 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.
  • K Offline
    K Offline
    Kelv1n
    wrote on last edited by
    #1

    Hi All

    I'm just starting to toy with PyQt5, its just a simple program that recursively scans a path and then populates QStandardItemModel which is attached to a TreeView, its works OK, but when sorting the tree it hangs until complete (and given the size, it can be a few seconds).

    So I read using QSortFilterProxyModel can help fix, which it does and UI no longer hangs.. But instead, I'm seeing some off behaviour, as you can see in the screenshot. I'm seeing gaps in the tree, there is no Row there (I've debugged the tree content and there is nothing), also the selection bar is not redrawing correctly (if I scroll the tree, this forces redraw correctly).

    Has anybody else ran into this? I've upgrade both Qt and PyQT and the same problem is occuring. Has anybody got any thoughts on this? Is there anyway I can force a redraw on-selection? (it's a hack, but still)

    0_1539550604324_Screenshot_2018-10-14 21.50.14_Z3PUPn.png

    Thanks
    Kelvin

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Out of curiosity, why not use QFileSystemMdel ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kelv1n
        wrote on last edited by Kelv1n
        #3

        Hi SGaist

        Thanks for replying (to this and my last post).

        The purpose of this program is to recurse the directory tree and show the size of all sub-content (a poor imitation of of TreeSize for Window), QFileSystemModel does not do this.

        I'm trying to write code which leaves the UI responsive, both when scanning the directory tree and when sorting, the scanning works quite well, but the only way I've found not to freeze up the UI when sorting is via the QSortFilterProxyModel, but I immediately started having the problem and have spent 2 weeks bashing my head against a wall trying to find a solution.

        JonBJ 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then what about moving the loading part in its own thread ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • K Kelv1n

            Hi SGaist

            Thanks for replying (to this and my last post).

            The purpose of this program is to recurse the directory tree and show the size of all sub-content (a poor imitation of of TreeSize for Window), QFileSystemModel does not do this.

            I'm trying to write code which leaves the UI responsive, both when scanning the directory tree and when sorting, the scanning works quite well, but the only way I've found not to freeze up the UI when sorting is via the QSortFilterProxyModel, but I immediately started having the problem and have spent 2 weeks bashing my head against a wall trying to find a solution.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @Kelv1n

            I'm trying to write code which leaves the UI responsive, both when scanning the directory tree and when sorting, the scanning works quite well,

            It's easy to leave the UI responsive during the scanning phase.

            Am I right in guessing: during the scanning phase you read all file paths from the disk, but do not update the UI (though maybe it remains responsive)? Then you do the complete sort, without updating the UI? So that at the end you can show a view of all the files in the system, sorted by something arbitrary like size?

            If you're trying to be like Win TreeSize, I'm thinking you'll want to read, sort & update the display all the time as you go along? I think as it reads directories it updates whatever it's sorted by as that is at that stage during the on-going reading. So "incomplete" or "incremental" sorting? If that's so I would be thinking of doing your own sorting as you go along, forcing the view to update sequentially?

            P.S.

            and given the size, it can be a few seconds

            Not when I use TreeView on my C:\ --- it can take minutes!

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kelv1n
              wrote on last edited by Kelv1n
              #6

              @JonB @SGaist Thanks for taking the time to reply. Sorry I've done a bad job of explaining.. The issue is not with the scanning or sorting at scan time.

              I'm using a QRunner thread which recursively scans the directory tree, then creates QStandardItem for each file/directory/symlink and puts them into a QStandardItemModel, which is associated with a QTreeView - The scanning and initial sorting (whilst scanning) work perfectly fine.

              Cnce scanning is complete, a user can use the column headers to change the sorting (i.e. via Name or Type), if I rely upon the default sorting, it causes the UI to freeze whilst the sort is processed. If I use a QSortFilterProxyModel, this freezing does not happen (UI remains interactive and sort is much quicker), but, the problem is, I'm getting the on-selection glitch that I showed above (if I scroll the tree or resize the window, it forces a redraw and fixes it self).

              I would provide the code.. but, it's a hell of a mess (this is not my day job, I'm just experimenting/playing in the evenings)

              I've come to the conclusion its a bug / anomaly as I've got the same issue with both PyQT5 and PySide2.. So think I'm going to put this to bed, and move onto something else.

              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