Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Refreshing content of QTableWidget



  • Hello,
    I have subclass of QDialog with QTableWidget. This dialog is modeless and it is in dock. I need to refresh content of QTableWidget when this dialog is not focused and user works with other dock. Table is refreshed only when get focus by user click, or when I minimalize/maximalize application window.

    I tried to call from inside of dialog member function
    item->setData() ;
    update()/repaint(); - not working.
    ui->myTableWidget->update()/repain(); - not working.
    ui->myTableWidget->viewport()->update(); - it works !

    I read documentation and looked through forums and every wrote that update()/repaint() should refresh content.
    So I have doubt that ui->myTableWidget->viewport()->update(); is correct way or is it ?


  • Lifetime Qt Champion

    Hi
    For a QTableWidget/view the viewport is the class drawing the visible items.
    But it sounds very odd you manually have to call update() on it.
    Normally that is never needed.

    By not updating, you mean you from outside inserts new items and they are not showing before
    user click on Table?



  • @mrjj Yes, parent dialog has public member function and it calls setText() on some cells of child QTableWidget. When QTableWidget get focus then it redraws content of all cells. (without calling ui->myTableWidget->viewport()->update())

    Can be problem that setText() is called from subclass of QThread and not from main application thread ?


  • Lifetime Qt Champion

    Hi,

    Don't call GUI objects method from other threads. If you want to modify some text from another thread then use signals and slots.



  • @SGaist Thank you, problem solved.


Log in to reply