# Issue with qSlicerWebWidget in python scripted extensions

**URL:** <https://discourse.slicer.org/t/issue-with-qslicerwebwidget-in-python-scripted-extensions/23413>\
**Category:** Development\
**Tags:** python\
**Created:** [May 13, 2022, 4:40pm UTC](https://discourse.slicer.org/t/issue-with-qslicerwebwidget-in-python-scripted-extensions/23413 "2022-05-13T16:40:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![im\_catta](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/im_catta/32/15300_2.png) [@im\_catta](https://discourse.slicer.org/u/im_catta)\
**Post date:** [May 13, 2022, 4:40pm UTC](https://discourse.slicer.org/t/issue-with-qslicerwebwidget-in-python-scripted-extensions/23413/1 "2022-05-13T16:40:48Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [May 13, 2022, 5:08pm UTC](https://discourse.slicer.org/t/issue-with-qslicerwebwidget-in-python-scripted-extensions/23413/2 "2022-05-13T17:08:35Z")

</div>

Try adding `slicer.app.processEvents()` after setting the url so the widget has a chance to render.

---

<div class="post-metadata">

**Author:** ![im\_catta](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/im_catta/32/15300_2.png) [@im\_catta](https://discourse.slicer.org/u/im_catta)\
**Post date:** [May 17, 2022, 11:50am UTC](https://discourse.slicer.org/t/issue-with-qslicerwebwidget-in-python-scripted-extensions/23413/3 "2022-05-17T11:50:11Z")

</div>

I tried using `slicer.app.processEvents()`, but the same problem remains

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [May 17, 2022, 1:00pm UTC](https://discourse.slicer.org/t/issue-with-qslicerwebwidget-in-python-scripted-extensions/23413/4 "2022-05-17T13:00:45Z")

</div>

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](https://apidocs.slicer.org/master/classqSlicerWebWidget.html)

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [May 17, 2022, 1:48pm UTC](https://discourse.slicer.org/t/issue-with-qslicerwebwidget-in-python-scripted-extensions/23413/5 "2022-05-17T13:48:06Z")

</div>

An example of use along with relevant signal connection is available at [Does WebWidget's printToPdf work on Mac?](https://discourse.slicer.org/t/does-webwidgets-printtopdf-work-on-mac/19544)

It may be helpful to move forward.
