Actually, just found your comment on this post. And have figured out how to handle keyboard press events. An example that decreases brush diameter when “M” is pressed is shown below:
import qt import slicer PARAM_DIAM = "BrushAbsoluteDiameter" def decreaseDiameter(): segmentEditorWidget = slicer.qMRMLSegmentEditorWidget() segmentEditorWidget.setMRMLScene(slicer.mrmlScene) segmentEditorNode = slicer.mrmlScene.GetSingletonNode("SegmentEditor", "vtkMRMLSegmentEditorNode") slicer.mrmlScene.AddNode(segmentEditorNode) segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode) segmentEditorWidget.setActiveEffectByName("Paint") effect = segmentEditorWidget.activeEffect() currentDiam = float(effect.parameter(PARAM_DIAM)) newDiam = currentDiam - 0.5 print("decreasing to new diam of %0.2f" % newDiam) effect.setParameter(PARAM_DIAM, newDiam) effect.forceRender shortcutDecrease = qt.QShortcut(slicer.util.mainWindow()) shortcutDecrease.setKey(qt.QKeySequence("M")) shortcutDecrease.connect("activated()", decreaseDiameter)
However, I am having a problem where the brush diameter does not refresh until I move the mouse. Is there a way to force this to repaint?