How to update QTableWidget immediately?



  • 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?



  • @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.


  • Lifetime Qt Champion

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.