Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Unsolved How to update QTableWidget immediately?

    General and Desktop
    3
    3
    2450
    Loading More Posts
    • 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.
    • tomweb
      tomweb last edited by

      Hello,
      I have a task, startet by user using signal-slot functionality which takes about 5-20 seconds.
      This task is mainly a for-next-statement, which calculates some things and fills a QTableWidget with the result, that means about 200 Items.
      I want, that the single result items are immedialely displayed. I can do this by calling "myTableWidget->repaint()" .
      But that causes the whole window to repaint (even is the visible area is full) and that makes it very very slow (2..3 times slower), compared without using ->repaint().
      But without repaint the Widget is only repainted after the for-next Statement (after that 5..20 seconds)
      I tried already a timer and repaint all 200ms, but that is not much better.
      ->update() does not help. Without repaint() the widget is only refreshed after i return from my slot (and after the for-next-statement is finished)

      Is there a easy way, to update/repaint ONLY the new items (i only append them at the end) in the QTableWidget? (like Explorer search for files....that list is updated immediately when some new files are found)
      I do not want to create a new task...i do not need to replay to user action during filling the TableWidget (no scrolling necessary till i finished)...and i do not want to use QTableView....

      is there still a possibility?

      ? 1 Reply Last reply Reply Quote 0
      • ?
        A Former User @tomweb last edited by

        @tomweb Hi, and welcome to the Qt forum! You could try calling void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents) instead of repaint(). Maybe that's faster.

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi and welcome to devnet,

          What about creating a loop through signals and slots ? That way you can keep your UI responsive.

          For example :

          
          void MyClass::processData()
          {
              if (_itemList.isEmpty()) {
                  return;
              }
              int next = _itemList.takeFirst();
              // process
              _tableWidget->setItem(row, col, new QTableWidgetItem(processingResult));
              QTimer::singleShot(this, 0, &processData)
          }
          

          You can even make tweak it and make it interruptible if needed.

          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 Reply Quote 1
          • First post
            Last post