Issue with qSlicerWebWidget in python scripted extensions

If want to generate a pdf file using the qSlicerWebWidget I can simply type in the Python Interactor something like

w = slicer.qSlicerWebWidget()
w.webView().url = qt.QUrl("")

but if I run the same code from a ScriptedLoadableModuleWidget it will not create the pdf. Moreover, no error message or exception is presented.

A similar behaviour applies if I want to .show() a qSlicerWebWidget. It’s working from the Python Interactor, but not from extensions.

What am I missing?

Try adding after setting the url so the widget has a chance to render.

1 Like

I tried using, but the same problem remains

You probably need more event processing. The best is to write the code in an asynchronous style, where you wait to process the page when it finishes loading. See the Signals section here:

An example of use along with relevant signal connection is available at Does WebWidget's printToPdf work on Mac?

It may be helpful to move forward.