有没有办法访问 QWidget 后备存储中的图像? [英] Is there a way to access the image on the QWidget's backing store?

查看:36
本文介绍了有没有办法访问 QWidget 后备存储中的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自定义小部件中的 paintEvent() 内部进行一些合成.一些合成是在一些区域已经绘制时完成的,我需要访问到目前为止绘制的当前内容.

I'm doing some compositing inside the paintEvent() in a custom widget. Some of the compositing is done when some areas are already painted, and I need access to the current contents painted so far.

因此,我正在寻找一种在 paintEvent 期间访问当前后备存储的图像内容的方法.我看过 QBackingStore,但没有什么可以直接让我访问后备存储位图.是否有一些 API(可能是私有的)可用于提供该功能?

So, I'm looking for a way to access the image contents of the current backing store during a paintEvent. I've looked at QBackingStore, but there's nothing there that directly gives me access to the backing store bitmap. Is there some API, perhaps private, that could be used to provide that?

如果没有,我将不得不求助于在显式像素图上绘制并将该像素图渲染到小部件上.

If not, I'll have to resort to painting on an explicit pixmap and rendering that pixmap onto the widget.

推荐答案

有可能,但不可移植.QBackingStore 只是在大多数平台上围绕 QImage 缓冲区的包装类,但我认为这并不能保证.我在编写 QuickWidget 时研究过这个问题.需要演员表:

It is possible, but it is not portable. The QBackingStore is just a wrapper class around a QImage buffer on most platforms, but I suppose this is not guaranteed. I've researched this issue when writing the QuickWidget. A cast is needed:

QImage * image = dynamic_cast<QImage*>(backingStore()->paintDevice());
if (image != 0) // it's an image, do something with it

注意不要导致 QImage 分离.诸如调整大小之类的事情是禁止的.

Be careful though not to cause the QImage to detach. Things such as resizing are off limits.

在以下位置检查 QuickWidget:

https://code.google.com/p/quickwidget/

这篇关于有没有办法访问 QWidget 后备存储中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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