How to block the user selection of a node in a qMRMLNodeComboBox?

Hello !!!

I’m trying to prevent the user to select a node in a qMRMLNodeComboBox. I think it should be an object within this class to block the selection of nodes.

I would appreciate if someone can help me.

Thank you very much.

You can filter what MRML nodes are displayed by calling addAtribute. You can show/hide nodes that have certain attribute value.

Are there any example of this? I can’t manage to do this and I can’t find any use case that implements this.

You need to set an attribute value on MRML nodes that you want to show. Nodes that do not have this attribute set or the value does not match will not show up in the node selector.

You can use tests in Slicer core as examples: https://github.com/Slicer/Slicer/search?q=addattribute&unscoped_q=addattribute

Let us know if you have any suggestions how to improve documentation to make this more clear.

1 Like

Ah, is an MRML attribute! I was using a shnode attribute. Now it works, thanks!

        self.Image2 = slicer.qMRMLNodeComboBox()
        self.Image2.nodeTypes = ["vtkMRMLScalarVolumeNode"]
        self.Image2.addAttribute("vtkMRMLScalarVolumeNode", "DICOM.Modality", "RTDOSE")
1 Like