Main Window Not Redrawing Until Clicked
-
I have an application that has a main window defined by Creator that has a QTableView used to show a list of objects' characteristics.
The application receives data through a serial port that can update an object's characteristics, so I want the list to be update d when this happens. The problem I'm having is that the application's main window is not the focus when a change occurs and does not update when the information arrives. If I click on the application's window to give it focus, it will redraw at that moment.
I have tried using both repaint() as well as update() for both the main window as well as the QTableView object, but all of these don't update the window until it is clicked on.
This needs to update when the window is in the background or is the focus. I don't know what I'm missing.
-
Please provide some code - how do you update your model. Do you properly emit the needed signals?
https://doc.qt.io/qt-6/model-view-programming.html#an-editable-model -
Yes, the signal is emitted with this:
emit RequestRedraw();
This is called when something has changed.
The signal is connected to the slot when the main window is initialized:
QObject::connect( pDoc, SIGNAL( RequestRedraw ), this, SLOT( update() ) );
The QTableView (ElementView) is a child of the main window, so I tried changing the connect call to use it directly:
QObject::connect( pDoc, SIGNAL( RequestRedraw ), ui->ElementView, SLOT( update() ) );
This had the same effect: the update was not visible until the window was clicked on.
The list model is NOT editable, as that would be impracticable since many of the fields displayed are status information (i.e. not something that can be edited by the user). This is also why it needs to be updated, whether the window is the focus or not.
-
@Calvin-H-C said in Main Window Not Redrawing Until Clicked:
Yes, the signal is emitted with this:
This is not what the documentation tells you what has to be emitted when data in the model changes. Please read and follow the documentation. There are also enough examples out there.