Patrice Bernassola
Patrice Bernassola

Reputation: 14446

Center QGraphicsView in Widget

I have a QDialog that contains several dock widgets and one QGraphicsView. The widget layout is set to grid, the QGraphicsView size policy is set to fixed on the 2 axes and it the QGraphicsView is center in the empty zone of the QDialog.

I would like to resize my QGraphicsView and let it at the center of the empty zone of the QDialog. I have tried this code:

// resize QGraphicsView
ui->mProjectView->resize(mProject->getSize() + QSize(2,2));

But QGraphicsView is adjusting its size to QDialog when resizing QDialog.

I'va tried then this:

// resize QGraphicsView
ui->mProjectView->resize(mProject->getSize() + QSize(2,2));
// Adjust size of QDialog to fit new widget's size
ui->centralWidget->adjustSize();

But this does not work. QGraphics View keeps last size...

I'm sure the way to achieve it is simple but I'm missing something. Can you help please?

Upvotes: 1

Views: 1721

Answers (1)

Troubadour
Troubadour

Reputation: 13431

You could try

ui->mProjectView->setFixedSize(mProject->getSize() + QSize(2,2));

instead.

Upvotes: 2

Related Questions