Remove Interaction toolbar from QMRMLSliceWidget

I would like to remove the toolbar from the qMRMLSliceWidget for a cleaner UI for a project I am working on. Is there a way to do this on the widget or should I display the slice by another method.

For reference this is the toolbar I am referring to.
Capture

AFAIK there’s no option exposed for that. It would be a bit of a hack (but not unprecedented) to use findChild at the qt in python level to remove the pushpin widget so the popup would never appear.

Thats a good thought. I will try that.

Having trouble finding documentation on the children of QMRMLSliceWidget. Is there somewhere that outlines this? Or a way to get a list of all children? calling findChildren(’*’) yielded empty result.

You could also doing something like this:

for viewName in ["Green", "Red", "Yellow"]:
  slicer.app.layoutManager().sliceWidget(viewName).sliceController().setVisible(False)

You can also use slicer.util.setViewControllersVisible(False) in recent Preview Releases.

If you want to create a Slicer-based application with a customized look&feel then you’ll probably find this page useful: https://www.slicer.org/wiki/Documentation/Nightly/Developers/Slicelets

@Iassoan , I did look into the slicelet templates. I am following basically this approach, but currently building the UI a different way. Having everything for my module on the sidebar and having the layout always visible next to it doesnt work for my application.

I am currently building a guided screen which opens several screens that get some user input, then I display a custom display consisting of QMRMLSliceWidgets.

1 Like

Continuing on this track, I want to add my own interaction widgets to the top of the slice view.

Im considering a few paths.

  1. I create my own widget in c++ that is similar to the qMRMLSliceWidget
    2.I build essentially the same thing in python using qMRMLSliceView - so far I only get a slicer crash when in do a show of a sliceview
    3.I hide the toolbar and simply place my buttons above the qMRMLSliceWidget in my layout.

Any thoughts on these approaches? I think 3 is easiest, but doesnt allow me to embed some of the logic in the view itself, but I havent been able to get very far with option 2.

You can customize widgets in the existing slice controller widgets any way you need: you can hide any built-in widget and add your own, as shown in the examples in script repository.

Getting a layout issue when I remove the widgets using the method in the script repository. The slice view becomes very small and the 3D grows to cover most of the space.

Is this expected?

Yes, it works as expected. You must to set up size policies in your Qt widgets according to what you need. Setting up size policies is not simple but it is standard Qt matter - there is nothing Slicer specific about how Qt widgets are sized in Slicer. See documentation here.