Slice widget size in custom layouts

I’m trying to change slice view sizes as part of the setup of a custom layout. For instance:

def formatCustomLayout(self):
    customLayout = ( XML code )
    layoutNode = slicer.app.layoutManager().layoutLogic().GetLayoutNode()
    customLayoutId = 500
    layoutNode.AddLayoutDescription(customLayoutId, customLayout)
    slicer.app.layoutManager().setLayout(customLayoutId)

    slicer.app.layoutManager().sliceWidget('Long2').mrmlSliceNode().SetDimensions(100, 100, 1)
#end formatCustomLayout

A picture is attached, rather than including all the XML code for the custom layout. I didn’t see any property tags that set the initial size of the slice widgets.
What I’d like to do is make the height of L1 twice the height of L2, without having to manually adjust the slider between them. However, it seems that packing the MRML widget happens after the line where I set the dimensions.
How do I change the size of slice widgets within a layout from a script, or alternatively, specify relative size in XML property tags?
Thanks for any assistance.

You cannot specify size hints in the XML, but it would be certainly very useful to add that. The relevant code is here.

Alternatively, you can use grid layouts and with row and column spans you may be able to get the view sizes you need. Also, you may try to access widgets and set size policies (you can access the widgets by slicer.app.layoutManager().sliceWidget(name) and slicer.app.layoutManager().threeDWidget(n)).

1 Like

Thanks, I’d forgotten that the slice and threeD widgets inherit from QWidget, so their size policies can be changed. I can adjust the initial size that way.
Thanks again,

Hey Michael,
Can you please post a snippet of the XML code layout you used to generate this view? Thank you!

You can use the splitSize attribute to determine relative height/width of views in layouts. For example: