# Qt Designer doesn't work for Python code preview

**URL:** https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342
**Category:** Development
**Created:** [October 31, 2020, 1:18am UTC](https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342 "2020-10-31T01:18:40Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)
#### Post date: [October 31, 2020, 1:18am UTC](https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342/1 "2020-10-31T01:18:40Z")

</div>

The error happens as follows:  
Create “NewExtension” with Extension Wizard  
Add Module to Extension “NewModule”  
Go to Modules combobox, go to Examples-\>NewModule  
Go to Edit UI (Qt Designer opens)  
Go to Form-\>View Python Code…

It gives the following error:

 ![error](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/7/b7e4ec8da721e5e149af258e4bebca1a59f9e304.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [October 31, 2020, 1:36am UTC](https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342/2 "2020-10-31T01:36:25Z")

</div>

What Slicer version and operating system do you use? Have you built Slicer yourself?

---

<div class="post-metadata">

### Author: ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)
#### Post date: [October 31, 2020, 2:10pm UTC](https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342/3 "2020-10-31T14:10:22Z")

</div>

Slicer version is 4.11.20200930 and Windows version is Windows 10 Pro x64.  
I haven’t built Slicer myself because I wasn’t able to get the dependencies going. This is the installer version

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [October 31, 2020, 5:42pm UTC](https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342/4 "2020-10-31T17:42:39Z")

</div>

Can you check if it works in the latest Slicer Preview Release? (there were some fixes related to this)

The Preview Release still has a few major issues, but you may just use its Qt Designer.

---

<div class="post-metadata">

### Author: ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)
#### Post date: [October 31, 2020, 6:05pm UTC](https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342/5 "2020-10-31T18:05:46Z")

</div>

Yes, Andras. I have checked and it doesn’t work on the Preview Release.  
Also if you select Form-\>View C++ Code… it shows the same error.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [October 31, 2020, 6:39pm UTC](https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342/6 "2020-10-31T18:39:29Z")

</div>

> [@mau\_igna\_06](#):
>
> Go to Form-\>View Python Code…

I’ve just realized that you are trying to generate some Python code. This is not needed! In Slicer, we developed a much simpler method for using .ui files in Python directly, using `slicer.util.loadUI` and `slicer.util.childWidgetVariables` functions, as it is shown in the module template.

You get the error because Python code generation requires the `uic` compiler, which we don’t bundle with Slicer, as it should not be necessary.

---

<div class="post-metadata">

### Author: ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)
#### Post date: [October 31, 2020, 8:49pm UTC](https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342/7 "2020-10-31T20:49:04Z")

</div>

Thank you Andras for clarifing the matter. I wanted to review the code because I wanted to make a coded UI but no problem, I’ll stick to .ui desing in Qt Designer.  
Is there a tutorial to create a script with .ui GUI? because I don’t know what to write in some methods that are automatically created and [this](https://docs.google.com/presentation/d/1JXIfs0rAM7DwZAho57Jqz14MRn2BIMrjB17Uj_7Yztc) tutorial I’m using creates the UI through code and looks much simpler

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 16, 2020, 6:03am UTC](https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342/8 "2020-12-16T06:03:40Z")

</div>

Using the designer reduces the size of a scripted module by 20-30%. Having less code means less code to debug and maintain. Using a visual designer also allows the developer on nicer, more intuitive GUI, while generating from code tends to result in GUI that the developer can create more easily, but it is worse for the users. I would recommend [this](https://slicer--5344.org.readthedocs.build/en/5344/developer_guide/api.html#id1) developer tutorial.

---

<div class="post-metadata">

### Author: ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)
#### Post date: [December 16, 2020, 3:19pm UTC](https://discourse.slicer.org/t/qt-designer-doesnt-work-for-python-code-preview/14342/9 "2020-12-16T15:19:52Z")

</div>

Thank you Andras. I checked it out a little bit but I’ll read it more carefully when I have a little more time. Until now I was only using [this](https://apidocs.slicer.org/master/) to check out classes definitions and [this](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository) for some code examples. Now I have another resourse 😃
