0
votes

This sounds like a question that's been asked here before, but I can't seem to find what I"m looking for.

So, I've got a vertical layout containing a QGraphicsView. I'm trying to implement the ability for the user to resize the view given any size they want. Like in MSPaint, you can choose an exact size for the canvas.

When I run the program, this works perfectly the first time, and on the vertical layout, I get a QGraphicsView of the exact size I specified, however, when the function resizeCanvas is called at runtime, I don't get the same effect.

Instead, I the QGraphicsView will either look like it's the same size if the specified values were greater than the existing ones (Like setting an 800x600 QGraphicsScene being changed to a 400x300),

or if the opposite is true (a 400x300 QGraphicsScene being changed to an 800x600), I'll get scrollbars rather than a bigger QGraphicsView widget.

canvasScene = new QGraphicsScene(this);
resizeCanvas(canvasWidth, canvasHeight);
void MainWindow::resizeCanvas(int x, int y) {
    canvasWidth = x;
    canvasHeight = y;
    canvasScene->setSceneRect(100, 100, canvasWidth, canvasHeight);
    updateCanvas();
}
void MainWindow::updateCanvas() {
    ui->canvas->setScene(canvasScene);
}

How can I make it resize the actual widget?

1

1 Answers

1
votes

My solution was simply to set the geometry of the QGraphicsView to the new values given