QTableView inside QTabWidget does not update UI after model data changes until user clicks inside the tab widget

  • I have a form with a QTabWidget and a QPushButton.

    Inside the QTabWidget I have a QWidget with a QTableView.

    Clicking the QPushButton updates the values in the table model.

    The problem is that after clicking the button, the table UI does not show any changes. Once you click anywhere inside the QTabWidget, that's when the table updates its display to show the new values. So in other words, the changes in the model are happening but they are not being updated until the user clicks somewhere inside the QTabWidget.

    I have tried using setFocus() on the QTabWidget and its child tab QWidget but neither have worked.

  • Moderators

    how exactly do you update the data in the table model?
    You need to make sure that you emit the dataChanged() signal out of the model in order to tell the view that it needs to repaint a cell.

  • I update the data with model()->setData(). The model does indeed emit dataChanged(). Like I said, the table data instantly updates in the UI once you click anywhere in the tab widget. The data is set but not shown.

  • I had to use QTableView::repaint() to solve the problem.

  • Moderators

    [quote author="jmalicke" date="1422403767"]I had to use QTableView::repaint() to solve the problem.[/quote]
    But you should avoid such calls in general, since it is an indicator for false code design if you need to do this.

    Please post the code of the setData() method.

Log in to reply

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