QgraphicsView不适合QT中的窗口
我有QgraphicsView,它具有多个Qgraphictem的。当我的视图首次加载并在屏幕上可见时,它不能完全适合屏幕。大约80%的视图可见。然后,我需要使用滚动来查看其余20%的视图。
在加载时,我的整个视图将如何可见?
我尝试以下方式:
(将所有项目添加到视图之后),
QRectF a = scene->sceneRect();
view->ensureVisible(a,200,200);
但我的视图仍然可见80%。
I am having QGraphicsView, which has multiple QGraphicsItem's. When my view loads first time and gets visible on screen, it can not be fit fully in the screen. Around 80% of view gets visible. Then I need to use scrolling to see the remaining 20% of the view.
How my whole view will get visible at the time of loading ?
I tried following way :
(After adding all the items into view )
QRectF a = scene->sceneRect();
view->ensureVisible(a,200,200);
But still my view is 80% visible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,关闭滚动条,可以通过以下方式实现以下操作:
qgraphicsView
实例。如果您将所有添加的项目都添加到场景中,请使用scenerect将所有添加的项目的bouding rect缩小到场景中,并且视图的几何形状 - 视图的可绘制窗口小部件由
viewport()
方法访问。 。当您具有场景几何形状和视图几何形状时,您可以计算可以通过
qgraphicsview :: scale()
方法应用于视图的比例因子。计算比例因子的算法(一个比例因子对于垂直轴和水平轴,因为我们不想在某些轴上伸展视图)如下:
最小代码
: TVIEW :: RESIZEEVENT您可以放入功能中并在需要时调用它:
First of all, turn off the scroll bars, it can be achived by:
called on
QGraphicsView
instance.If you have all added items to the scene, use sceneRect to get bouding rect of all added items to the scene, and the geometry of the view - drawable widget of the view is accessed by
viewport()
method.When you have the scene geometry and the view geometry you can compute the scale factor which can be applied to the view by
QGraphicsView::scale()
method.The algo to compute the scale factor (one scale factor for both vertical and horizontal axis because we don't want to stretch content of view in some axis) is as follows:
Minimal code:
The code contained in TView::resizeEvent you can put in the function and call it when it is required: