如何在 Qt 中实现类似 Google 地图的平铺滚动?
我正在使用 Qt/C++ 并尝试绘制一个大型且复杂的 QGraphicsScene。一旦我添加了很多对象,平移和缩放就会变得非常慢。 (当然,这并不奇怪)。我尝试过设备坐标缓存(有助于平移到某个点)和最小视口更新等等,但最终对象太多了。我想做的是通过某种方式控制 UI 异步绘制项目。换句话说,就像 Google 地图一样,我想要平移和缩放,让绘图尽可能快地跟上,但能够在项目完成绘制之前再次平移。
我尝试的一种方法是创建两个 QGraphicsScene。一个拥有实际的对象,但没有附加到 QGraphicsView。另一个 QGraphicsScene 连接到 QGraphicsView,但它只有一些平铺的 QPixmap,其大小可以覆盖屏幕。计划是使用空闲的 CPU 周期来更新任何需要它的图块像素图。这似乎会给我对渲染的必要控制(所以我不必在重新渲染整个可见场景时阻塞)。想法?有人实施过这个吗?
I'm using Qt/C++ and trying to draw a large and complex QGraphicsScene. Once I add a lot of objects, panning and zooming become unpleasantly slow. (No surprise here, of course). I've played with device coordinate caching (helps with panning to a point) and minimal viewport updates and so on, but eventually there's just too many objects. What I'd like to do is draw the items asynchronously from controlling the UI somehow. In other words, just like Google Maps does, I want to pan and zoom and let drawing catch up as fast as it's able, but to be able to pan again before the items finish drawing.
One method I'm trying is to create two QGraphicsScenes. One has the actual objects but is not attached to a QGraphicsView. The other QGraphicsScene is connected to the QGraphicsView, but it just has some tiled QPixmaps that are sized to cover the screen. The plan is to use spare CPU cycles to update any tile pixmap that needs it. This seems like it will give me the necessary control over rendering (so I don't have to block while re-rendering the entire visible scene). Thoughts? Has anyone implemented this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下这里:在线程中生成内容。
听起来这与您正在尝试做的事情类似。平铺机制是加载大量数据的非常常见的方法。除了发布的链接之外,我还没有看到使用 QGraphicsView 的简单示例。
40000 筹码还展示了一些有关管理大额资金的内容的数据。
Take a look here: Generating content in threads.
It sounds like this is similar to what you are trying to do. Tile mechanisms are very common ways to load in large amounts of data. Other than the link posted, I have not seen a simple example using
QGraphicsView
.40000 Chips also shows some things about managing large amounts of data.