Render Visual Subtree to QImage
-
Hey,
First of all, some background:
I'm working on overlaying a Qt widget on top of a widget that does 3D rendering using the OGRE 3D library.
Unfortunately, that means that I can't simply add the widgets as children to the 3D rendering widget because setting the background to transparent won't work this way.
Qt can't access the pixel information from the 3D library, so, setting the background to transparent will only show what's below the Qt Application rather than the content of the 3D widget.
In Qt4 I could solve this by using the PaintOutsidePaintEvent attribute and rendering the widget into an image that I could put on top of the 3D scene using methods provided by OGRE.Now, my problem is that I have to transition to Qt5 and the attribute mentioned above doesn't exist anymore.
How can I render a QWidget including its subtree in a QImage while preserving keyboard and mouse interaction in Qt5?Thanks in advance!
Best,
StefanEdit: In case that it matters, I'm on Ubuntu 16.04 and it only has to work on linux.
-
Since posting this I made some progress.
I am able to render content and I think I can make mouse and keyboard interaction work if I flesh out what is currently just experimentation.
However, the widget for some reason fills the widgets area with a black background.
Any idea how I can prevent that and instead keep the background transparent? -
@StefanFabian I am also facing same issue. Actually I have upgraded my project from Qt4 to Qt5 and OGRE from 1.8.0 to 1.11.6. In Old version I am able to see 2D dimensions which I have render on OGRE view using following code but now I am unable to see 2D dimensions on OGRE view so I am not able to understand weather this issue is regarding Qt or OGRE. please suggest any solution
// Get the pixel buffer. Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mHudTexture->getBuffer(0,0); // Lock the pixel buffer and get a pixel box. pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); Ogre::uint8* pDest = static_cast<Ogre::uint8*> (pixelBox.data); // Construct HUD image directly in the texture buffer. { // Create empty transparent image the size of the ogre window.
QImage hud(pDest, mHudTexture->getWidth(), mHudTexture->getHeight(), QImage::Format_ARGB32);
hud.fill(Qt::transparent);// Use a Qt QPainter to render to the ogre texture. QPainter painter(&hud);