im_catta
(Andrea Cattaneo)
May 13, 2022, 4:40pm
1
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("https://www.slicer.org/")
w.printToPdf(r"C:\foo\page.pdf")
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?
pieper
(Steve Pieper (Isomics, Inc.))
May 13, 2022, 5:08pm
2
Try adding slicer.app.processEvents()
after setting the url so the widget has a chance to render.
1 Like
im_catta
(Andrea Cattaneo)
May 17, 2022, 11:50am
3
I tried using slicer.app.processEvents()
, but the same problem remains
pieper
(Steve Pieper (Isomics, Inc.))
May 17, 2022, 1:00pm
4
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:
https://apidocs.slicer.org/master/classqSlicerWebWidget.html
jcfr
(Jean Christophe Fillion Robin (Kitware))
May 17, 2022, 1:48pm
5
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.