Is there a way to access the image on the QWidget's backing store?

故事扮演 提交于 2019-12-17 09:57:35

问题


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.

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.


回答1:


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

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

Check the QuickWidget out at:

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



来源:https://stackoverflow.com/questions/18724391/is-there-a-way-to-access-the-image-on-the-qwidgets-backing-store

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!