Switch from module using c++

Hello,

Seems simple but i did not find how to switch module programatically.

Let’s say i receive a signal containing data, then i create a node, fill it correctly. How can switch automatically to the module “data” ?

Can I also change the node visibility ?

In general, a module should not initiate switching to another module, as each module should implement a particular feature completely. If you are working on a module that performs a complex workflow then you can place all relevant widgets in your module GUI.

For example, if you want to show a data tree then you don’t switch to the data module, just add a data tree to the widget of your module:

v = slicer.qMRMLSubjectHierarchyTreeView()
v.setMRMLScene(slicer.mrmlScene)
v.show()

You can customize what columns are shown in the tree, filter which items are displayed, define actions that are performed when the user selects an item, etc.

If you still think that switching modules is appropriate (e.g., at the end of your workflow), you can do what is done in the Welcome module:

Hello indeed maybe it’s the best solution, but i did not manage to get it work.

I added qMRMLSubjectHierarchyTreeView to my module widget but i couldn’t get to the actual dataTree. What would be a C++ equivalent of v = slicer.qMRMLSubjectHierarchyTreeView(), i did not found a tree view in qSlicerApplication::**** .

Thank you

If you start Qt designer (Slicer.exe --designer) then qMRMLSubjectHierarchyTreeView should show up in the widget list and you can just drag-and-drop it into your GUI.

Yes, but my question was more about how connect my GUI treeview to the original data module one.

There is no need to connect the widgets to each other, just set the scene in the widget.

OK, thank you it works nicely indeed.

1 Like