- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经阅读了关于它们的文档,但我仍然不清楚实际的区别是什么。 ItemCoordinateCache 的文档说明:
Caching is enabled for the item's logical (local) coordinate system.
对于 QGraphicsItem::DeviceCoordinateCache:
Caching is enabled at the paint device level, in device coordinates. This mode is for items that can move, but are not rotated, scaled or sheared.
这并没有为我解决问题。好的,所以 DeviceCoordinateCache 不能用于旋转、缩放或剪切,它使用“设备坐标”。
但这到底是什么意思呢?有一个屏幕外缓冲区,我假设对于本地坐标,缓冲区充满了项目的缓存图像,然后像 QGraphicsPixmapItem 一样工作,并且应用了不透明度和变换矩阵等任何效果。我认为问题是这会栅格化项目的图像,所以这就是文档警告它不会像素完美的原因。
但是它如何与 DeviceCoordinateCache 一起工作?项目是先旋转、剪切和缩放然后绘制在屏幕外的像素图上,还是它在像素图上呈现相同但没有应用任何转换?
编辑:我还尝试将 DeviceCoordinateCache 设置为旋转和缩放的项目,它显示完美,即使我调整了它的大小,所以我不明白为什么文档说不应该使用它带有缩放、旋转或剪切的项目。
最佳答案
There is an off-screen buffer, and I assume for local coordinates the buffer is filled with the item's cached image, and then acts like a QGraphicsPixmapItem and any effects such as opacity and the transform matrix are applied to it. I assume the problem is that this rasterizes the item's image so that's why the docs warn that it won't be pixel-perfect.
没错。缓存以您使用 setCacheMode() 指定的选择质量存储在内存中。后续转换不会使缓存失效,它会被重用,这就是质量会下降的原因。如果它恶化太多,您可以通过使用更大的大小再次调用 setCacheMode() 使缓存无效。
But how does it work with a DeviceCoordinateCache? Is the item first rotated, sheared and scaled and then painted on the off-screen pixmap
再一次,您做对了:应用转换,然后将结果直接缓存在设备内存中。缓存始终以最高质量执行。但是,除了移动之外的任何新转换都会使缓存无效,这使我们想到了您的最后一句话:
Also I tried setting DeviceCoordinateCache to a rotated and scaled item and it displayed perfectly, even when I resized it, so I don't understand why the docs say it shouldn't be used with scaled, rotated or sheared items.
除移动之外的任何新转换都会使缓存失效。它仍然有效,并且始终可以完美显示,但效率不高:每次调整大小时都会强制使用新的缓存。
如果您不总是变换项目,请使用 DeviceCoordinateCache。如果这样做,请使用 ItemCoordinateCache 或根本不使用任何缓存。
关于qt - QGraphicsItem中的ItemCoordinateCache和DeviceCoordinateCache有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39342492/
我是一名优秀的程序员,十分优秀!