Screenshotting a hidden external view widget

I have an external view widget I created with the code here but I never call because I want it hidden from the user.

If I try to get a screenshot of the external slice view widget with vtkWindowToImageFilter the vtkImage is of size 0,0,1. If I use img = ctk.ctkWidgetsUtils.grabWidget the image is the right size and shows the colored scroll bar on top, but the slice image is completely black.

I always call and view_widget.sliceView().forceRender() before screenshotting but it still doesn’t function. Any suggestions?


You may need to show the widget at least once to complete its initialization. You might also need to temporarily show it when you take a screenshot, in which case you could try set the window position outside of the screen or below the main window to prevent it from popping up for the user.

Showing the widget and then immediately hiding it right after creation does not work unfortunately. I can however screenshot when the widget is outside of the monitor bounds, so I’ve just used qwidget.setGeometry to put it out of bounds