Call a widget's methods in Python

jhlegarreta
Sat, 16 Dec 2023 20:03:35 +0000
SlicerDMRI

Hello,

For the purposes of building a test, I am wondering whether there is a way to instantiate and call the methods from a class that inherits from qSlicerWidget​ (e.g. qSlicerTractographyDisplayWidget​, which lives in SlicerDMRI, and which has its Qt Designer UI file here) programmatically from Python.

I am able to do the below:

m = slicer.util.mainWindow()
m.moduleSelector().selectModule("TractographyDisplay")
display_widget = slicer.util.findChildren(name="qSlicerTractographyDisplayModuleWidget")[0]

but when trying to call any of the qSlicerTractographyDisplayWidget methods, e.g.:

opacity = display_widget.opacity()
display_widget.updateWidgetFromMRML()

it looks like I am querying the wrong object:

AttributeError: qSlicerTractographyDisplayWidget has no attribute named 'opacity'

AttributeError: qSlicerTractographyDisplayWidget has no attribute named 'updateWidgetFromMRML'

What am I missing?

Thanks.

4 posts - 2 participants