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. [Helped, if not solved!] sizeHintForColumn eating all the CPU (presumably by being called an awful lot)
QtWS25 Last Chance

[Helped, if not solved!] sizeHintForColumn eating all the CPU (presumably by being called an awful lot)

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.1k Views
  • 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
    Moschops
    wrote on last edited by
    #1

    I have a QTreeView, and it gets populated with information. Not an enormous amount, but as far as I can tell (not having written it) it looks like a standard QTreeView, being given a model derived from a QAbstractItemModel.

    The QTreeView shows two columns, one of which contains the expandable tree bits and the other contains some subsidiary information. As time goes on, new items can be inserted, and they will either be inserted at the bottom, or if they go with something already in the model, rows get added.

    For example, it's information about files, and it might end up looking something like this:

    @file_one.cpp DONE
    |__ info A
    file_two.cpp DONE
    |__info B@

    and then the next update will be "info MORE" for file_one.cpp, so then the on screen view becomes

    @file_one.cpp DONE
    |__ info A
    |__ info MORE
    file_two.cpp DONE
    |__info B@

    All pretty simple. There could be thousands and thousands of these; there is a big queue of messages being processed, and each one adds something to the model.

    It's taking forever. So I profiled it (expecting to see that the message processing was slow, or some other such, but I've played this game before and I know that the only facts come from measuring), using perf, and one function is taking up 70% of the time; QTreeView::sizeHintForColumn

    My guess is that this gets called every time something is inserted, because the QTreeView wants to resize the column. Is that right? If so, is it something I can stop or optimise?

    Alternatively, could I tell the QTreeView not to update while the queue of messages is being processed? I think that might be acceptable; to just show them all once the queue is finished.

    I've got various ideas, but I'm not so stupid that I won't ask more experienced people :)

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

      Hi,

      If you know that all your rows have the same hight you can use the uniformRowHeights property of the QTreeView.

      Then you can optimize some more by doing batch updates rather than update each every row as fast as possible.

      Hope it helps

      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
      • M Offline
        M Offline
        Moschops
        wrote on last edited by
        #3

        I think I'm really hoping for some way to tell it not to bother resizing columns.

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

          You can try to play with QHeaderView::setResizeMode

          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
          • M Offline
            M Offline
            Moschops
            wrote on last edited by
            #5

            I think it has helped a bit, thanks.

            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