# Switch from module using c++

**URL:** <https://discourse.slicer.org/t/switch-from-module-using-c/8121>\
**Category:** Development\
**Created:** [August 21, 2019, 1:54pm UTC](https://discourse.slicer.org/t/switch-from-module-using-c/8121 "2019-08-21T13:54:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbahegne](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbahegne/32/4837_2.png) [@rbahegne](https://discourse.slicer.org/u/rbahegne)\
**Post date:** [August 21, 2019, 1:54pm UTC](https://discourse.slicer.org/t/switch-from-module-using-c/8121/1 "2019-08-21T13:54:47Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 21, 2019, 3:50pm UTC](https://discourse.slicer.org/t/switch-from-module-using-c/8121/2 "2019-08-21T15:50:40Z")

</div>

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:

```python
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:

> <https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/SlicerWelcome/qSlicerWelcomeModuleWidget.cxx#L156-L180>

---

<div class="post-metadata">

**Author:** ![rbahegne](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbahegne/32/4837_2.png) [@rbahegne](https://discourse.slicer.org/u/rbahegne)\
**Post date:** [October 7, 2019, 2:20pm UTC](https://discourse.slicer.org/t/switch-from-module-using-c/8121/3 "2019-10-07T14:20:31Z")

</div>

> [@lassoan](#):
>
> 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:
> 
> ```auto
> v = slicer.qMRMLSubjectHierarchyTreeView()
> v.setMRMLScene(slicer.mrmlScene)
> v.show()
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 7, 2019, 5:04pm UTC](https://discourse.slicer.org/t/switch-from-module-using-c/8121/4 "2019-10-07T17:04:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rbahegne](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbahegne/32/4837_2.png) [@rbahegne](https://discourse.slicer.org/u/rbahegne)\
**Post date:** [October 8, 2019, 7:43am UTC](https://discourse.slicer.org/t/switch-from-module-using-c/8121/5 "2019-10-08T07:43:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 8, 2019, 11:45am UTC](https://discourse.slicer.org/t/switch-from-module-using-c/8121/6 "2019-10-08T11:45:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rbahegne](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbahegne/32/4837_2.png) [@rbahegne](https://discourse.slicer.org/u/rbahegne)\
**Post date:** [October 8, 2019, 2:18pm UTC](https://discourse.slicer.org/t/switch-from-module-using-c/8121/7 "2019-10-08T14:18:09Z")

</div>

OK, thank you it works nicely indeed.
