I'm writing a very simple test program that when a push button is clicked, a GraphicsView will display an image, a grid layout is used. I want the window size adjust automatically according to the image size. The code is similar to
// load image and setup scene
// ...
ui->graphicsView->show();
ui->graphicsView->updateGeometry();
// adjustSize();
adjustSize();
The problem is that when adjustSize() is called, the window doesn't resize to correct size, and I have to call adjustSize() twice or display a QMessageBox before calling adjustSize() to resize the window to correct size. And btw resize(sizeHint()) gives the same result
I wonder why this is happening and is there an elegant way to do it correctly? Many thanks.