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 is too laggy during simple item hover (2-3 elements, 3 columns)
QtWS25 Last Chance

QTreeWidget is too laggy during simple item hover (2-3 elements, 3 columns)

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 756 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.
  • W Offline
    W Offline
    Wdowiak
    wrote on last edited by
    #1

    I am having a problem with a QTreeWidget, namely, when hovering over its items it gets laggy and the UI thread goes to 100% CPU usage as you can see in this video demonstration. The weird thing is, that I had only 2-3 elements in the tree widget. My CPU is old (I7-2600k), but it shouldn't choke on such a trivial task. The lag and high CPU usage occur even if the application is started without visual studio.

    Any ideas what could be wrong? (the QTreeWidget is initialized as its shown on its documentation site, since it was only a test)

    jsulmJ 1 Reply Last reply
    0
    • W Wdowiak

      I am having a problem with a QTreeWidget, namely, when hovering over its items it gets laggy and the UI thread goes to 100% CPU usage as you can see in this video demonstration. The weird thing is, that I had only 2-3 elements in the tree widget. My CPU is old (I7-2600k), but it shouldn't choke on such a trivial task. The lag and high CPU usage occur even if the application is started without visual studio.

      Any ideas what could be wrong? (the QTreeWidget is initialized as its shown on its documentation site, since it was only a test)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Wdowiak What else are you doing in your application? Do you react on any events? Did you connect any slots to any signals?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • W Offline
        W Offline
        Wdowiak
        wrote on last edited by
        #3

        @jsulm
        I am using CMake, C++17 and my own statically linked library (pure C++17 & STL). In CMake I only link Qt5::Widgets and Qt5::Charts.

        I have a worker thread in the statically linked library that constantly pools foreground window title & its executable path with 100ms intervals (std::this_thread::sleep_for(100ms)). If the foreground window changes, the thread invokes a callback (std::function & std::bind) that simply moves (std::move) the data(a couple of string and timestamps) into a std::vector, which didn't happen during the test, since the window didn't change. I've profiled the worker thread as well as tested it on console application and its shouldn't bottleneck anything.

        I am reading and writing from/to SQLite db. During the test, I've only queried the DB once, to get the data and no writes were done. The class for the db is also in the library.

        Atm. the MainWindow consists of central widget, vertical layout, chart view and the tree widget
        I have a chart view that displays stacked bar data. During the test there were only 25 data points.

        In the entire application I have only 4 signal/slot connections.:

        • QStackedBarSeries::clicked
        • QStackedBarSeries::doubleClicked -- called twice during the test
        • QSystemTrayIcon::activated
        • QAction::triggered - quit action added to QSystemTrayIcon

        I react on one event, namely, QMainWindow::closeEvent.
        So overall, it's a bare bones application since I have just started working on it.

        jsulmJ 1 Reply Last reply
        0
        • W Wdowiak

          @jsulm
          I am using CMake, C++17 and my own statically linked library (pure C++17 & STL). In CMake I only link Qt5::Widgets and Qt5::Charts.

          I have a worker thread in the statically linked library that constantly pools foreground window title & its executable path with 100ms intervals (std::this_thread::sleep_for(100ms)). If the foreground window changes, the thread invokes a callback (std::function & std::bind) that simply moves (std::move) the data(a couple of string and timestamps) into a std::vector, which didn't happen during the test, since the window didn't change. I've profiled the worker thread as well as tested it on console application and its shouldn't bottleneck anything.

          I am reading and writing from/to SQLite db. During the test, I've only queried the DB once, to get the data and no writes were done. The class for the db is also in the library.

          Atm. the MainWindow consists of central widget, vertical layout, chart view and the tree widget
          I have a chart view that displays stacked bar data. During the test there were only 25 data points.

          In the entire application I have only 4 signal/slot connections.:

          • QStackedBarSeries::clicked
          • QStackedBarSeries::doubleClicked -- called twice during the test
          • QSystemTrayIcon::activated
          • QAction::triggered - quit action added to QSystemTrayIcon

          I react on one event, namely, QMainWindow::closeEvent.
          So overall, it's a bare bones application since I have just started working on it.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Wdowiak You could try to comment out some parts of your code until this issue disappear. Then you would know where to look.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • W Offline
            W Offline
            Wdowiak
            wrote on last edited by
            #5

            I've tried it with most of my stuff disabled (worker thread, SQLite db and chart), but no change. I am downloading QT debug info, so I can pinpoint the problem, since without the symbols, it only shows that QApplication::exec() has 99% of the accounted samples. Unfortunately the downloading will take a while.

            jsulmJ 1 Reply Last reply
            0
            • W Wdowiak

              I've tried it with most of my stuff disabled (worker thread, SQLite db and chart), but no change. I am downloading QT debug info, so I can pinpoint the problem, since without the symbols, it only shows that QApplication::exec() has 99% of the accounted samples. Unfortunately the downloading will take a while.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Wdowiak Does a simple Qt Widgets app behave like this on your machine?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

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

                Hi,

                What version of Qt are you using ?
                What version of your OS is it ?
                One tool you can also try is KDAB's GammaRay

                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
                1
                • W Offline
                  W Offline
                  Wdowiak
                  wrote on last edited by
                  #8

                  @jsulm Just created a fresh app with QTreeWidget and 5 random elements, and it seems to be working fine (UI thread usage ~10%-20% during hovering)

                  @SGaist
                  hey,
                  I am using 5.13, but I have also tried changing Qt path in CMake to 5.12, same result.
                  Windows 10 Pro, 1903
                  GammaRay is compiling as we speak. Will definitely give it a try.

                  1 Reply Last reply
                  1
                  • W Offline
                    W Offline
                    Wdowiak
                    wrote on last edited by
                    #9

                    Found the culprit. I was still using an old db data which had a lot of data from initial library test. The initial string values were not shrunk and had a bunch of null terminating characters at the end (since I had to pre-allocate buffer that was passed to C-style WinAPI functions). After adding Qt source and debug symbol the culprit was obvious.

                    Basically, QTextEngine::shape was indirectly calling NtGdiGetCharWidthW that was choking on ~1k null terminating characters per string.
                    image

                    Didn't thought of that before, because I knew the strings were shrunk, but I guess a lot of not optimized data from the first tests were still in db.

                    Thank you guys for help, have a lovely day.

                    1 Reply Last reply
                    1

                    • Login

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