根据缩放级别渲染 QGraphicsScene [英] Render QGraphicsScene according to zoom level

查看:62
本文介绍了根据缩放级别渲染 QGraphicsScene的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有(快速?)方法可以根据视图缩放级别仅呈现 GraphicsScene 项目的子集?我有一个包含许多网格线的大场景,我想隐藏/显示其中的一些,当缩放更改以避免网格完全填充场景"效果时.

Is there a (quick?) way to render only a subset of GraphicsScene items according to View zoom level? I'm having a big scene with many grid lines and i want to hide/show some of them, when the zoom changes to avoid the 'grid completely fills the scene'-effect.

使用 GraphicsScene 的 addLine 方法绘制网格线.

Grid lines are drawn using addLine method of GraphicsScene.

附言也许,最简单的方法是在其他地方绘制网格(在视图中或类似的地方),因为从逻辑上讲它们不是我场景的一部分,它们只是指导线?但我不知道哪种方式更有效.

P.S. Maybe, the easiest way is to draw grid somewhere else (on view or smth like that), because logically they aren't a part of my scene, they are only guide-lines? But i don't know which way is more effective.

推荐答案

不建议这样创建网格,因为您将创建许多会影响场景 BSP 树的对象,因此它会很快变慢.它还会使像您描述的那样进行 LOD 缩放变得更加困难.

It's not advised to create the grid like that because you will be making many objects that will affect the scenes BSP tree, so it will get slow quickly. It will also make having an LOD zoom like you describe more difficult.

我会覆盖 QGraphicsView::drawBackground(QPainter*painter, const QRectF& rect),并使用场景坐标中的视图边界来计算您想要的网格线数量以及它们的位置.然后就可以像正常的绘画操作一样绘画了.

I would overwrite QGraphicsView::drawBackground(QPainter* painter, const QRectF& rect), and use the view's bounds in scene coordinates to calculate how many grid lines you want and where they are. Then just paint as normal painting operation.

您必须将更新模式设置为 QGraphicsView::FullViewportUpdate 否则您将在网格渲染中获得人工制品.

You will have to set the update mode to QGraphicsView::FullViewportUpdate otherwise you will get artefacts in the grid render.

这篇关于根据缩放级别渲染 QGraphicsScene的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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