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. How to update QTableWidget immediately?
Forum Updated to NodeBB v4.3 + New Features

How to update QTableWidget immediately?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 2.9k Views 2 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.
  • tomwebT Offline
    tomwebT Offline
    tomweb
    wrote on last edited by
    #1

    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
    0
    • tomwebT tomweb

      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?

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @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
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
        1

        • Login

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