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

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

      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

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

Instead, I suggest to update:

  • the code updating the launcher settings when installing an extension. See here
  • the code generating the AdditionalLauncherSettingsPath used when starting Slicer with a specific extension. See here

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

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.

1 Like

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?

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

[...]

[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.

Edit: right. Nevermind!

@adamrankin Thanks again for submitting PR#1084 :+1:

After applying few tweaks it has been integrated in r28325 and issue #4670 has been resolved.