NA-MIC Project WeeksBug description:
Here is a sample script that connect a qtMRMLComboBox node to a parameter node, and creating a subjectHierarchy folder to add the parameter node to it. Both will be set to ‘None’
import slicer, qt
dialog = qt.QDialog(slicer.util.mainWindow())
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)
shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
def printState(tag):
print(f"\n[{tag}]")
print(" shComboBox.currentItem():", shComboBox.currentItem())
print(" shComboBox.currentNode():", repr(shComboBox.currentNode()))
# Add the parameter node to a folder
def onRun():
currentItemID = shComboBox.currentItem()
if currentItemID == 0:
print("No selection (currentItemID==0)")
return
printState("BEFORE MOVE")
folderItemID = shNode.CreateFolderItem(shNode.GetSceneItemID(), "SHCombo_TestFolder")
shNode.SetItemParent(currentItemID, folderItemID)
printState("AFTER MOVE (post SetItemParent)")
runButton.clicked.connect(onRun)
dialog.show()
[AFTER MOVE (post SetItemParent)]
shComboBox.currentItem(): 0
shComboBox.currentNode(): None
parameter.selectedFiducial: None
If qt combobox signal is blocked using qt.QSignalBlocker, then parameter node will not be set to ‘None’
beginMoveRows and endMoveRows. This will probably be the correct solution if we can me it work (first attempt is not robust, something is missing)No response
No response