Setting up the qMRML Segment editor Widget in ui

Slicer version: 5.0.2

Hello everyone,

I have been trying to add the segment editor widget within my own module for user convenience. So far, I have been able to create the widget and have it appear in a popup window. Here is a picture of what was done so far:

However, I wanted to use the Segment Editor Widget I added to my UI. But I am unable to initiate and setup it up. Here is another screenshot showing the widget I want to use:

pic 2

If anyone could help me it would be greatly appreciated. Thanks!

You need to make sure from your module that the segment editor widget has:

  • The MRMLScene set (editor.setMRMLScene())
  • A segment editor parameter node (editor.setMRMLSegmentEditorNode())

If you are using the Qt designer you can use that to set up a connection to the setMRMLScene slot from the parent widget. The latter will have to be done in Python. You can see an example of this in the SegmentEditor module: Slicer/SegmentEditor.py at 6931e0d9820a86be8c97f77225bdd3a479980820 · Slicer/Slicer · GitHub

Hey Kyle, thank you very much for the quick answer!!! I’ll try this and get back to you to see if I can get it to work.

Hello again,

So I implemented the code and set the MRMLscene and parameter node for the Segment Editor Widget as well as adding the connection on qt designer.

However, none of the methods seem to work. I linked the code I added as well as the connection I made:

P.S - I made sure to add the selectParameterNode(self) function as well.

I am not sure where the error comes from. If there is anything else you need please let me know. Thank you again!

If you set slicer.mrmlScene in Python then it doesn’t need to be done in the Qt designer as well.
Can you confirm that selectParameterNode() is run and self.parameterSetNode is not None?

If you still have issues then you can post or email me a link to the code and I can take a look at it.

Hello Kyle,

I apologize for the late response. I tested the function and can assure you that the selectParameterNode() function runs and self.paramaterSetNode is not None type.

I did however realize that the code does create a segment editor widget and if I type self.editor.show(), it appears in another popup window. However, it fails to instead make the connection with the segment editor widget implemented in my UI. I believe the problem comes from the following lines :

import qSlicerSegmentationsModuleWidgetsPythonQt
self.editor = qSlicerSegmentationsModuleWidgetsPythonQt.qMRMLSegmentEditorWidget()

Instead of creating a new widget, I would have to connect the Segment Editor functionality to the widget in my UI. Is there a way to access the widget from the UI file in python?

If that’s alright, I’ll also email you my code. Thank you again for everything.

Hello,

I am looking at this discussion, by any chance, were you able to resolve this issue ?
I am not able to connect the segment editor in a customized GUI.
If you have a working code snippet (python), this would be very useful.

Thanks!

If I recall, the issue was that there was an editor widget in the UI file and another that was created in Python that was not added to the module widget.

You need to make sure that your widget is connected to the mrmlScene, and has a segment editor node. The SegmentEditor module is probably the best resource for seeing how to use the widget. Slicer/SegmentEditor.py at 6931e0d9820a86be8c97f77225bdd3a479980820 · Slicer/Slicer · GitHub.

Can you be more specific about the problem that you are having?