Unsolved Qt button clicked slot is omniscient?
-
So this is strange, when the code below is implemented, upon pushing the button, it will sleep first and then set the graphics view scene to the newScene. I made the hiddenSleepFunction when this was happening with Sleep() instead of the hidden function, however the clicked function still elects to sleep first and then execute the rest of the code? what?
void CanvasTest::on_pushButton_2_clicked() { QGraphicsScene* scene = ui->PixMapView->scene(); QGraphicsScene* newScene = new QGraphicsScene(0,0,200,300); ui->PixMapView->setScene(newScene); hiddenSleepFunction(); // ui->PixMapView->setScene(scene); } void hiddenSleepFunction() { Sleep(4000); }
-
Hi,
Repainting is not an immediate action. Basically you are blocking the event loop so refreshing the GUI wit your new scene will only happen after the loop has run which will be after your Sleep call.
-
huh well that's interesting, thanks for the reply. Is there programming terminology for the fact that repainting isn't an immediate action? I just don't understand why this is so.
-
@SGaist Also one other question if I may. I'm also trying to scale the pixmap I have in my graphics view widget using ui->graphicsviewObject->scale(xfactor,yfactor) however all this seems to accomplish is breaking my pixmaps and displaying a blank white page. Does this relate to the fact that repainting is not an immediate action (it never displays the pixmap though for clarity).
-
It's explained in the QWidget::paintEvent method documentation.
You are scaling the view not the pixmap itself.
-
@Brazzoni said in Qt button clicked slot is omniscient?:
I just don't understand why this is so
Because as @SGaist said you're blocking the event loop. If event loop is blocked events (including paint events) are not handled.
One of most important rules using asynchronous frameworks like Qt is: do not block the event loop.