Show/Hide slice views widget

Hi,
This topic is from this discussion previously:
Show/Hide Slice Views
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

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.

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

Could you please tell any updates regarding this issue.

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

You can copy paste this into the Python console:

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.

1 Like

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:

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

Another way to do it is:

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.