Slicer 5.10 qMRMLSubjectHierarchyComboBox turned to 'None' but no issue with 5.8.1

Sorry for the late response. Thank you very much for your advice and time!

Yes. Initially, I could not repeat the same bug directly in the Python console but only in an extension. After some tests, the snippet finally worked and could repeat the same issue:

To run with the snippet below, in a fresh Slicer 5.10 scene,

  1. Create a markup fiducial node
  2. Copy-paste the below snippet in the Python console,
  3. In the pop-up GUI, select the node in the combo box, and click the button below it.

#Copy-paste below snippet in the Python console:

import slicer, qt
from slicer.parameterNodeWrapper import parameterNodeWrapper

@parameterNodeWrapper
class SHTestParameters:
    selectedFiducial: slicer.vtkMRMLMarkupsFiducialNode

dialog = qt.QDialog(slicer.util.mainWindow())
dialog.setWindowTitle("SHComboBox move -> GUI reset -> Param wipe test")
layout = qt.QVBoxLayout(dialog)

shComboBox = slicer.qMRMLSubjectHierarchyComboBox()
shComboBox.nodeTypes = ["vtkMRMLMarkupsFiducialNode"]
shComboBox.noneEnabled = True
shComboBox.setMRMLScene(slicer.mrmlScene)

layout.addWidget(qt.QLabel("Select a fiducial (SubjectHierarchyComboBox):"))
layout.addWidget(shComboBox)

runButton = qt.QPushButton("Move selected node into folder (triggers reset)")
layout.addWidget(runButton)

parameterNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScriptedModuleNode", "SHCombo_ParamNode_Test")
parameter = SHTestParameters(parameterNode)

shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)

def printState(tag):
    print(f"\n[{tag}]")
    print("  shComboBox.currentItem():", shComboBox.currentItem())
    print("  shComboBox.currentNode():", shComboBox.currentNode())
    print("  parameter.selectedFiducial:", parameter.selectedFiducial)

# sync combo box to the parameter node similar to the original module
def onComboChanged(itemId):
    node = shNode.GetItemDataNode(itemId)
    parameter.selectedFiducial = node
    printState("Combo changed (GUI->param sync fired)")

shComboBox.connect("currentItemChanged(vtkIdType)", onComboChanged)

#Add the parameter node to a folder
def onRun():
    currentItemID = shComboBox.currentItem()
    if currentItemID == 0:
        print("No selection (currentItemID==0)")
        return

    # seed parameter node explicitly (like your "store orbitLm/plateLm first")
    parameter.selectedFiducial = shNode.GetItemDataNode(currentItemID)

    printState("BEFORE MOVE")

    folderItemID = shNode.CreateFolderItem(shNode.GetSceneItemID(), "SHCombo_TestFolder")
    shNode.SetItemParent(currentItemID, folderItemID)

    printState("AFTER MOVE (post SetItemParent)")

runButton.connect("clicked()", onRun)

dialog.show()
dialog.raise_()
dialog.activateWindow()


You should see that the node is put under a newly created folder, but the comboBox is reset to ‘None’

In Python console, you should see parameter node set to None because the parameter node is synced with the combobox by def onComboChanged the as in the original module:

[AFTER MOVE (post SetItemParent)]
shComboBox.currentItem(): 0
shComboBox.currentNode(): None
parameter.selectedFiducial: None

Interestingly, in the same scene, when I simply ran the same function again, the combobox did not set to ‘None’ afterwards. The error only happened when run the function first time in a fresh Slicer scene.

Let me know if this one works.