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

**URL:** <https://discourse.slicer.org/t/how-to-allocate-the-proportion-of-window-occupied-by-each-slicewidget/30797>\
**Category:** Development\
**Created:** [July 26, 2023, 9:17am UTC](https://discourse.slicer.org/t/how-to-allocate-the-proportion-of-window-occupied-by-each-slicewidget/30797 "2023-07-26T09:17:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [July 26, 2023, 9:17am UTC](https://discourse.slicer.org/t/how-to-allocate-the-proportion-of-window-occupied-by-each-slicewidget/30797/1 "2023-07-26T09:17:19Z")

</div>

i use the code below to custom 3d slicer layout

```auto
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](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/d/dd0f61bc3560a9c90563faf7b02576e3805c96af.png)

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/d/3d16ac027d50da7a281927edc6a15bc74350e6d1.png)

---

<div class="post-metadata">

**Author:** ![icedream](https://avatars.discourse-cdn.com/v4/letter/i/48db29/32.png) [@icedream](https://discourse.slicer.org/u/icedream)\
**Post date:** [July 28, 2023, 1:44am UTC](https://discourse.slicer.org/t/how-to-allocate-the-proportion-of-window-occupied-by-each-slicewidget/30797/2 "2023-07-28T01:44:56Z")

</div>

i use splitsize 500 by 500,it works fine!

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [July 28, 2023, 5:23am UTC](https://discourse.slicer.org/t/how-to-allocate-the-proportion-of-window-occupied-by-each-slicewidget/30797/3 "2023-07-28T05:23:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![icedream](https://avatars.discourse-cdn.com/v4/letter/i/48db29/32.png) [@icedream](https://discourse.slicer.org/u/icedream)\
**Post date:** [July 30, 2023, 8:18am UTC](https://discourse.slicer.org/t/how-to-allocate-the-proportion-of-window-occupied-by-each-slicewidget/30797/4 "2023-07-30T08:18:06Z")

</div>

yes,the result is inaccurate

---

<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:** [July 31, 2023, 1:46am UTC](https://discourse.slicer.org/t/how-to-allocate-the-proportion-of-window-occupied-by-each-slicewidget/30797/5 "2023-07-31T01:46:54Z")

</div>

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](https://doc.qt.io/qt-6/qsplitter.html). 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.

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [July 31, 2023, 1:51am UTC](https://discourse.slicer.org/t/how-to-allocate-the-proportion-of-window-occupied-by-each-slicewidget/30797/6 "2023-07-31T01:51:14Z")

</div>

thank you lassoan, This answer is very professional !

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [July 31, 2023, 3:44am UTC](https://discourse.slicer.org/t/how-to-allocate-the-proportion-of-window-occupied-by-each-slicewidget/30797/7 "2023-07-31T03:44:11Z")

</div>

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