我将QGraphicsView子类化,并在我的布局中显示小部件。 在视图中我自然有QGraphicsScene。
我可以完美地检索QGraphicsScene大小(即像我设置的2100x2970),但QGraphicsView小部件的几何不正确。 每当我调整主窗口的大小时,布局都会发生变化,视图窗口小部件也会发生变化。 当然,QGraphicsScene的大小无关紧要,无论它是什么。 但是通过视口显示滚动条和场景的小部件并没有为我提供正确的小部件宽度和高度。
在QtDesigner中,QGraphicsView小部件显示QWidget几何体为1126x643。 但我永远无法在子类QGraphicsView类中检索这些值。
当我知道宽度(1126或主窗口调整大小时的其他内容)时,我可以计算视图的比例因子(比例因子= 1126/2100),以使场景覆盖视图窗口小部件的整个宽度。
在QGraphicsView中:
qDebug("scene: %f %f", scene()->width(), scene()->height()); // works (2100x2970) qDebug("geo: %f %f", geometry().width(), geometry().height()); // does not (0x2970)I subclassed QGraphicsView and show the widget in my layout. Within the view I naturally have QGraphicsScene.
I can retrieve the QGraphicsScene size perfectly fine (namely 2100x2970 like I set), however the geometry of the QGraphicsView widget is incorrect. Whenever I resize the main window, the layout changes and so does the view widget change. Of course, the size of QGraphicsScene is irrelevant and stays whatever it is. But the widget showing the scrollbars and the scene through the viewport just doesn't provide me with the correct widget width and height.
In the QtDesigner the QGraphicsView widget shows to have QWidget geometry of 1126x643. But I can never retrieve these values in the subclassed QGraphicsView class.
When I know the width (1126 or something else when main window is resized) I can calculate the scale factor for the view (scale factor = 1126 / 2100) to get the scene to cover the full width of the view widget.
In QGraphicsView:
qDebug("scene: %f %f", scene()->width(), scene()->height()); // works (2100x2970) qDebug("geo: %f %f", geometry().width(), geometry().height()); // does not (0x2970)最满意答案
你看过QGraphicsView :: fitInView()吗? 此方法将自动为您执行所需的比例计算。
Have you looked at QGraphicsView::fitInView()? This method will do the needed scale calculations for you automatically.
更多推荐
发布评论