# \[Help Request\] QFormBuilder was unable to create a custom widget

**URL:** <https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389>\
**Category:** Development\
**Created:** [January 16, 2019, 5:12pm UTC](https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389 "2019-01-16T17:12:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [January 16, 2019, 5:12pm UTC](https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389/1 "2019-01-16T17:12:27Z")

</div>

Hello,

Has anyone experienced this error? The widget is question works in another C++ module, but fails when using python and a .ui file

`QFormBuilder was unable to create a custom widget of the class 'qMRMLVideoCameraIntrinsicsWidget'; defaulting to base class 'qSlicerWidget'.`

Edit: code to load UI

```python
      scriptedModulesPath = eval('slicer.modules.%s.path' % self.moduleName.lower())
      scriptedModulesPath = os.path.dirname(scriptedModulesPath)
      path = os.path.join(scriptedModulesPath, 'Resources', 'UI', 'q' + self.moduleName + 'Widget.ui')
      self.widget = slicer.util.loadUI(path)

```

Edit2: my workaround is to have a placeholder QWidget in the .ui file, and to create the custom widget in code after loading the UI

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [January 16, 2019, 5:36pm UTC](https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389/2 "2019-01-16T17:36:16Z")

</div>

It looks like QFormBuilder/QUiLoader needs the plugin path to contain the \*Plugin.dll file. The current implementation has `C:\Program Files\Slicer 4.10.0\bin\designer` and `C:\Program Files\Slicer 4.10.0\lib\QtPlugins\designer` in the path.

Two potential solutions are to extend `slicer.util.loadUI(filePath)` to also accept additional plugin directories, or to copy all `*Plugin.dll` files from an extension into the above folders, or to intelligently add an extensions `QtPlugin` directory to the plugin path in `slicer.util.loadUI`

---

<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:** [January 16, 2019, 5:42pm UTC](https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389/3 "2019-01-16T17:42:38Z")

</div>

Instead, I suggest to update:

- the code updating the launcher settings when installing an extension. See [here](https://github.com/Slicer/Slicer/blob/be03b25aa21ac68e3bbb1b591ada3f8800c6b9f5/Base/QTCore/qSlicerExtensionsManagerModel.cxx#L634)
- the code generating the AdditionalLauncherSettingsPath used when starting Slicer with a specific extension. See [here](https://github.com/Slicer/Slicer/blob/master/Extensions/CMake/SlicerBlockAdditionalLauncherSettings.cmake)

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [January 16, 2019, 5:43pm UTC](https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389/4 "2019-01-16T17:43:45Z")

</div>

Do you think QFormBuilder uses the current path to load Qt plugins?

---

<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:** [January 16, 2019, 5:45pm UTC](https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389/5 "2019-01-16T17:45:54Z")

</div>

Path that contains the plugin mud be added to the env. variable `QT_PLUGIN_PATH`. Dependencies of the plugin must also be added to `PATH`, `LD_LIBRARY_PATH` or `DYLD_LIBRARY_PATH` depending on the plaform. This last point is most likely already taking care of.

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [January 16, 2019, 5:57pm UTC](https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389/6 "2019-01-16T17:57:01Z")

</div>

Would you recommend to add a [QtPluginPaths] section to an extensions AdditionalLauncherSettings.ini, or adding it to an existing entry ([Paths], [LibraryPaths]) and loading those to the QT\_PLUGIN\_PATH env var?

---

<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:** [January 16, 2019, 6:01pm UTC](https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389/7 "2019-01-16T18:01:44Z")

</div>

To clarify, here is a snippet of the current `SlicerLauncherSettings.ini` found in the build tree :

```auto
[...]

[Environment]
additionalPathVariables=QT_PLUGIN_PATH,PYTHONPATH

[...]

[QT_PLUGIN_PATH]
1\path=<APPLAUNCHER_SETTINGS_DIR>/bin
2\path=/home/jcfr/Projects/Slicer-Qt5-VTK9-RelWithDebInfo/CTK-build/CTK-build/bin
3\path=/home/jcfr/Software/Qt5.11.1/5.11.1/gcc_64/plugins
size=3

[...]

```

This means that a env. variable `QT_PLUGIN_PATH` will be set before starting Slicer. Each one of these paths a subdirectory named `designer`. The same thing should be done in `AdditionalLauncherSettings.ini`.

Then the launcher will take of creating a unified environment before starting the application.

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [January 16, 2019, 7:22pm UTC](https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389/8 "2019-01-16T19:22:57Z")

</div>

Edit: right. Nevermind!

---

<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:** [June 21, 2019, 6:57am UTC](https://discourse.slicer.org/t/help-request-qformbuilder-was-unable-to-create-a-custom-widget/5389/9 "2019-06-21T06:57:14Z")

</div>

@adamrankin Thanks again for submitting [PR#1084](https://github.com/Slicer/Slicer/pull/1084) 👍

After applying few tweaks it has been integrated in [r28325](http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=28325) and issue [#4670](https://issues.slicer.org/view.php?id=4670) has been resolved.
