如何在 QGraphicsview 中平移超出滚动条范围? [英] How to pan beyond the scrollbar range in a QGraphicsview?

查看:52
本文介绍了如何在 QGraphicsview 中平移超出滚动条范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 QGraphicsView 中构建节点图,目前正在实施平移.我使用以下问题如何在 QGraphicsView 中平移图像"开始但平移受滚动条范围的限制.

I am building a node graph in a QGraphicsView and I am currently implementing panning. I used the following question "how to pan images in QGraphicsView" to start but the panning is limited by the scrollbar range.

我也尝试了 translate 方法,但它给出了相同的结果.视图仅限于某个矩形.

I also tried the translate method but it gives the same result. The view is limited to a certain rectangle.

我想无限制地平移,图形可以变得非常大,并且能够在场景的不同区域(这里一个图形,那里另一个图形等)工作非常有用.

I would like to pan without limits, the graph can becomes quite large and it is useful to be able to work in different area of the scene (one graph here, another graph over there, etc).

推荐答案

如果你看看 此视频,在 3 分钟标记处,您将看到平移屏幕的演示.这里的应用程序是我开发的,虽然没有显示出来,但在平移时,板子的空间似乎是无限的.

If you take a look at this video, at the 3 minute mark you'll see the demonstration panning the screen. The application here is one I developed and although it doesn't show it, the real estate of the board appears limitless when panning.

我为此所做的是创建一个 32000 x 32000 的 QGraphicsScene,并以 QGraphicsScene 中心的视图启动应用程序.测试团队花了很长时间试图平移到图形场景的边缘,但在到达那里之前每个人都放弃了 - 也许场景可以更小!

What I did for this was to create a QGraphicsScene of 32000 x 32000 and start the application with the view at the centre of the QGraphicsScene. The test team spent ages trying to pan to the edge of the graphics scene and everyone gave up before getting there - perhaps the scene could have been smaller!

滚动条策略设置为关闭,转换是通过通过其转换函数移动 QGraphicsView 来完成的,传递在 mouseMoveEvent 中应用的触摸或鼠标移动的增量.

The scroll bar policies are set to off and translation is done by moving the QGraphicsView via its translate function, passing in the delta of either touch, or mouse movement that is applied in the mouseMoveEvent.

这样做,您不必担心超出滚动条范围,创建一个非常大的 QGraphicsScene 也没有问题,因为它只是一个坐标空间.

Done this way, you need not worry about exceeding the scroll bar range and there was no problem creating a very large QGraphicsScene as it's just a coordinate space.

这篇关于如何在 QGraphicsview 中平移超出滚动条范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆