How to allocate the proportion of window occupied by each slicewidget?

i use the code below to custom 3d slicer layout

def custom_layout(self):
    customLayout = """
      <layout type="vertical" split="true">
          <item splitSize="150">
            <layout type="horizontal">
            <item>
              <view class="vtkMRMLSliceNode" singletontag="Red">
              <property name="orientation" action="default">Axial</property>
              <property name="viewlabel" action="default">R</property>
              <property name="viewcolor" action="default">#F34A33</property>
              </view>
            </item>
            <item>
              <view class="vtkMRMLViewNode" singletontag="1">
              <property name="viewlabel" action="default">1</property>
              </view>
            </item>
            </layout>
          </item>
          <item splitSize="150">
            <layout type="horizontal" split="true">
            <item splitSize="130">
              <view class="vtkMRMLSliceNode" singletontag="Green">
                <property name="orientation" action="default">Coronal</property>
                <property name="viewlabel" action="default">G</property>
                <property name="viewcolor" action="default">#6EB04B</property>
              </view>
            </item>
            <item splitSize="20">
              <view class="vtkMRMLSliceNode" singletontag="Green2">
                <property name="orientation" action="default">Coronal</property>
                <property name="viewlabel" action="default">G</property>
                <property name="viewcolor" action="default">#6EB04B</property>
              </view>
            </item>
            </layout>
          </item>
      </layout>
    """
    customLayoutId=503
    layoutManager = slicer.app.layoutManager()
    layoutManager.layoutLogic().GetLayoutNode().AddLayoutDescription(customLayoutId, customLayout)
    layoutManager.setLayout(customLayoutId)

i want to make the proportion is 13:2
image

but the actual result is below,the proportion is more like 2:1,how to make the proportion to 13:2 then?

i use splitsize 500 by 500,it works fine!

If the ratio is close to 1, the result is correct, but if the ratio is less than 0.5, the result is inaccurate

1 Like

yes,the result is inaccurate

Everything works as it is supposed to, the issue is just layout sizing is an extremely complex topic. Layout is computed by Qt, taking into account hundreds of constraints (minimum/maximum sizes and stretch factors and size policies for every widget) that may be somewhat contradicting.

splitSize calls setSizes method of QSplitter. The sizes are absolute (defined in device-independent pixels). If you specify a smaller size than the minimum size (dictated by the slice view controller - the slider, buttons, labels above the image) then the splitSize has no effect. If you specify a larger size than the size than available in the view layout then Qt will try to respect the specified sizes as much as possible. If it is impossible to respect all the constraints then Qt will allocate the avaialable space according to the requested sizes: sections with larger splitSize will be allocated larger area. Therefore, to set a ratio of 1:2 between two widgets, you can set their sizes to 10000:20000.

Note that minimum widget sizes will still be respected. So, if you request size of 10000 and 50000 then the size ratio may not be 1:5 if that would make the first section smaller than the minimum size. Instead, the first section’s size will be set to the minimum size and the other section will get the remaining space.

1 Like

thank you lassoan, This answer is very professional !

1 Like

hide the controller bar of all slice widget , it can be adjust into a right size ratio,thank you lassoan for sugggestion!!

1 Like