简体   繁体   English

在布局上调整QGraphicsView小部件的大小

[英]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. 因此,我有一个包含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. 像在MSPaint中一样,您可以为画布选择确切的尺寸。

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. 当我运行该程序时,这在第一次运行时完美无缺,在垂直布局上,我得到的是我指定大小的QGraphicsView,但是,当在运行时调用函数resizeCanvas时,不会得到相同的效果。

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), 相反,如果指定的值大于现有的值,我的QGraphicsView看起来将是相同的大小(例如将800x600的QGraphicsScene设置为更改为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. 或者相反(如果将400x300 QGraphicsScene更改为800x600),我将获得滚动条,而不是更大的QGraphicsView小部件。

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的几何设置为给定的新值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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