简体   繁体   中英

Resize QGraphicsView widget on layout

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?

我的解决方案只是将QGraphicsView的几何设置为给定的新值

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM