# Show/Hide slice views widget

**URL:** <https://discourse.slicer.org/t/show-hide-slice-views-widget/13433>\
**Category:** Development\
**Created:** [September 11, 2020, 5:03am UTC](https://discourse.slicer.org/t/show-hide-slice-views-widget/13433 "2020-09-11T05:03:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sogo](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sogo](https://discourse.slicer.org/u/sogo)\
**Post date:** [September 11, 2020, 5:03am UTC](https://discourse.slicer.org/t/show-hide-slice-views-widget/13433/1 "2020-09-11T05:03:44Z")

</div>

Hi,  
This topic is from this discussion previously:  
[Show/Hide Slice Views](https://discourse.slicer.org/t/show-hide-slice-views-in-3d-view-using-python/3074/2)  
From this discussion, I found that it is possible to Show/Hide the (‘Red’ ‘Green’ ‘Yellow’) slice view widgets but it is not working for me. I’m trying to hide all the slice view widgets for my loadable module as it does not need it by using this code:

> vtkMRMLNode\* node = qSlicerApplication::application()-\>mrmlScene()-  
> GetNodeByID(“vtkMRMLSliceNodeYellow”);  
> vtkMRMLSliceNode \*sliceNode = vtkMRMLSliceNode::SafeDownCast(node);  
> sliceNode-\>SetSliceVisible(0);

but nothing happens when I call it.  
**Note: Currently trying for only yellow and if it works will do for the rest in for loop.**  
So I tried the above thread and put the commands in python interactor:

> red = getNode(‘vtkMRMLSliceNodeRed’)  
> red.SetSliceVisible(0)

But still it does not hide. I wanted to ask is it possible to hide the complete views panel so that the module panel can take all that space? Thanks

---

<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:** [September 11, 2020, 5:13am UTC](https://discourse.slicer.org/t/show-hide-slice-views-widget/13433/2 "2020-09-11T05:13:15Z")

</div>

`SetSliceVisible` controls visibility of a slice in the 3D view.

View widgets are standard Qt widgets, so you can call its `hide()` method to hide it. You can make the entire view layout go away by hiding parent widgets.

---

<div class="post-metadata">

**Author:** ![sogo](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sogo](https://discourse.slicer.org/u/sogo)\
**Post date:** [September 11, 2020, 8:53am UTC](https://discourse.slicer.org/t/show-hide-slice-views-widget/13433/3 "2020-09-11T08:53:57Z")

</div>

Hi Andras,  
Thanks for your response. Your comment got me looking for underlying widget. So I found the qSlicerMRMLWidget to be the widget setting up slice views panel and I was able to get underlying handle for the three views like this:

> qSlicerLayoutManager\* layoutManager = qSlicerApplication::application()-\>layoutManager();  
> qMRMLSliceWidget\* red = layoutManager-\>sliceWidget(“Red”);  
> qMRMLSliceWidget\* yellow = layoutManager-\>sliceWidget(“Yellow”);  
> qMRMLSliceWidget\* green = layoutManager-\>sliceWidget(“Green”);  
> red-\>hide();  
> yellow-\>hide();  
> green-\>hide();

Some issues so far are:  
1- This works well on linux centOS8 but not on windows 10. I will look into it a little more

---

<div class="post-metadata">

**Author:** ![trash\_imp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/trash_imp/32/11178_2.png) [@trash\_imp](https://discourse.slicer.org/u/trash_imp)\
**Post date:** [August 22, 2021, 2:38pm UTC](https://discourse.slicer.org/t/show-hide-slice-views-widget/13433/4 "2021-08-22T14:38:49Z")

</div>

> [@sogo](#):
>
> Some issues so far are:  
> 1- This works well on Linux centOS8 but not on windows 10. I will look into it a little more

Could you please tell any updates regarding this issue.

---

<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 23, 2021, 2:44pm UTC](https://discourse.slicer.org/t/show-hide-slice-views-widget/13433/5 "2021-08-23T14:44:02Z")

</div>

I can confirm that the code above works perfectly on Windows10, too.

You can copy paste this into the Python console:

```python
layoutManager = slicer.app.layoutManager()
red = layoutManager.sliceWidget("Red")
yellow = layoutManager.sliceWidget("Yellow")
green = layoutManager.sliceWidget("Green")
red.hide()
yellow.hide()
green.hide()

```

Most likely that the different behavior that you see is not due to operating system difference but in what layout you create and when you try to hide the widgets inside it. Most likely you hide the widgets before they are even shown, so hiding has no effect.

---

<div class="post-metadata">

**Author:** ![sogo](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sogo](https://discourse.slicer.org/u/sogo)\
**Post date:** [August 31, 2021, 12:03am UTC](https://discourse.slicer.org/t/show-hide-slice-views-widget/13433/6 "2021-08-31T00:03:33Z")

</div>

Hi @trash_imp  
Not sure if it will help but what I did to hide all the slice views was to get the underlying handle to the frame that populates all the slice views using this code and then hide that frame completely:

```auto
QFrame* frame = qobject_cast<QFrame*>(layout->sliceWidget("Red")->parent());
frame->hide();

```

Another way to do it is:

```auto
qSlicerApplication::application()->mainWindow()->
            findChild<QWidget*>("CentralWidget")->findChild<QFrame*>("CentralWidgetLayoutFrame")->hide();

```

I haven’t used the method as I went to do something different, but they both worked for me.
