Programmatically (python) define the values for the min and max of the slider in the volume widget (not the min-max of the window/level)

I am trying to define the minimum and maximum values of the slides in the volume widget (see screenshot - it is the widgets circled in red).

For clarity this is not the min-max of the WindowLevel.

Which widget do these elements belong to and how what is the most appropriate way to read/write them?

thanks

Once you have a qMRMLWindowLevelWidget object, you can use the setMinMaxBounds method.

import SampleData
volume_node = SampleData.SampleDataLogic().downloadMRHead()
window_level_widget = slicer.qMRMLWindowLevelWidget()  # creates a new window/level widget object
window_level_widget.setMRMLVolumeNode(volume_node)
window_level_widget.setMinMaxBounds(0,100)
window_level_widget.show()

You can also see discussion linked below about why you might use Window/Level values that are outside of the scalar range and why the values of -600 to 600 are chosen in the image you show.

1 Like

Thanks. That works!

The other part I am having trouble working out is how to identify and access the existing WindowLevelWidget that is associated with PET Scalar volume.

For reference below is how I worked out to access the existing window level widget.

Very interested to hear if there a better / cleaner approach. thanks.

ui = slicer.util.getModuleWidget("Volumes")
ui_children = slicer.util.childWidgetVariables(ui)
windowLevelWidget = ui_children.MRMLWindowLevelWidget
windowLevelWidget.setMinMaxBounds(0, 20)
1 Like