Creating a new segment editor widget causes strange behavior in segmentation settings

Creating a new segmentation and applying works as expected (it remains visible), but if you type in the python console:


then, creating a new segmentation and applying, will cause the “Slice fill” and “Slice outline” to be set to zero (settings in the Segmentation module advanced area).

So, the steps to reproduce are (using Slicer latest stable release 4.11.20210226 revision 29738 built 2021-03-01):

  1. Load any 2D image
  2. Go to the Data module, right click the image node and select “Segment this…”
  3. Add a segment, click the Threshold effect and apply. It will work as expected
  4. Go to the Data module and delete the segmentation node
  5. In the python console type: slicer.modules.segmenteditor.createNewWidgetRepresentation()
  6. Right click the image node and select “Segment this…”
  7. Add a segment, click the Threshold effect and apply. The segmentation will be invisible. You can then check the segmentation advanced settings to notice that “Slice fill” and “Slice outline” are set to zero

createNewWidgetRepresentation is only to be used by the application. A module or script should not ever need to duplicate the GUI of a module. You can simply instantiate a qMRMLSegmentEditorWidget and add it to your module (or just keep it hidden if you don’t need to show a GUI, as it is done in most of the segmentation examples in the script repository).

1 Like