Trying to grab/render a pixmap from a Qt3DWindow
-
I'm creating a Qt3DWindow in a window container, then using render() to get a pixmap from the window container (I can't render() from the Qt3DWindow itself because it's not a QWidget). When I save the pixmap to a PNG file it turns up empty. The 3D entities I added are nowhere to be seen.
I know there's a grabWindow function that might work, but it's not perfect because any windows that overlap the Qt3DWindow would be copied into the pixmap as well. Does anyone know how I can do this? Thanks.
self.extrude_window = Qt3DExtras.Qt3DWindow()
self._windowContainer = QtWidgets.QWidget.createWindowContainer(self.extrude_window)add graphical entities
pix = QtGui.QPixmap(self._windowContainer.width(), self._windowContainer.height())
self._windowContainer.render(pix)
pix.save(file_name, 'PNG') # resulting PNG file is empty -
Hi and welcome to devnet,
Was the widget ever shown before you call render ?
-
@SGaist The widget is visible at the time that render is called. I'm using PySide6, incidentally. There's also a QWindow in the same application for which the grab() function successfully obtains a pixmap with the correct contents.
-
Can you provide a minimal script example showing this behaviour ?
-
@SGaist
// create a Qt3DWindow
self.extrude_window = PySide6.Qt3DExtras.Qt3DWindow()
// put it in a window container to make it behave like a widget
self._windowContainer = QtWidgets.QWidget.createWindowContainer(self.extrude_window)// Add a series of QCuboidMesh entities to a root entity, then
// assign the root entity to the Qt3DWindow
// Assign a material and a transform to each of the cubic entities// Create a pixmap to hold the contents of the window container, which should theoretically include the contents of the Qt3DWindow as well
pix = QtGui.QPixmap(self._windowContainer.width(), self._windowContainer.height())
// Render the window container to the pixmap
self._windowContainer.render(pix)
// Save the pixmap to a PNG file
pix.save(file_name, 'PNG') # resulting PNG file is empty -
Also, the Qt3DWindow is one child of a QStackedWidget. The other child of the QStackedWidget is a QWindow, and as I mentioned before, the grab() of the QWindow returns a valid pixmap containing all of the window's contents (which are then successfully saved to a PNG file).
-
Update: I tried passing the QWidget.DrawChildren flag into _windowContainer.render() as the renderFlags argument. This time, instead of getting a blank PNG file from the pixmap, I got a PNG file of scrambled color streaks, as if the number of pixels per row in the image didn't match the horizontal resolution in the PNG.
-
Maybe this is important too: When the Qt3DWindow renders its shapes (to the display, not to the pixmap), there is a series of "Xlib: sequence lost (...) in reply type 0x0!" error messages.
-
Has any progress been made on this problem? I'm still encountering it. If it helps at all, I'm running on a Linux system with noVNC.