Access Color Node from Colors Widget (python)

Hi!

I managed to connect the colors widget via slicer.modules.colors.widgetRepresentation.
Now I want to use the color node from the ColorTableComboBox, but I can’t access it.

Basically, my code would be:
self.visualization_button.enabled = True
displayNode = self.uncertainty_selector.currentNode().GetScalarVolumeDisplayNode()
colormap = self.colormap_selector.ColorTableComboBox.getNode()
displayNode.SetAndObserveColorNodeID(colormap)

However, python can’t find this combobox. How can I access the colorNode?
Thanks in advance!

Operating system: Windows 10
Slicer version: 4.10.0

Would you like to change the currently selected color node in the Colors module? Or you would like to add a color table or a color node selector into your own module GUI?

I want to apply the currenty selected color node in the Colors Module to a displayNode via displayNode.SetAndBoserveColorNodeID(ColorNode), but I can’t access the selected colorNode.

EDIT:
In the source code of qSlicerColorsModuleWidget.cxx, there is a pointer d that is used to access the ColorTableComboBox from SlicerColorsModuleWidgetPrivate, like in Line 370, for example:
d->ColorTableComboBox->currentNode(). I want that exact node.

In general, you are not supposed to access GUI of other modules but instead you can communicate with them using MRML and module logic classes.

For selecting a color node, you can put a node selector widget on your module GUI. Would that work for you?

1 Like

I see, my bad.

I’ll try using the node selector widget, I guess that should work, too. Thank you!

1 Like

I did it!
I used the slicer.qMRMLColorPickerWidget() to select a premade color node and accessed it via .currentColorNode().GetID() to set it as the ColorNode for my DisplayNode. Thank you!

1 Like