# Set minimum view width/height in a layout

**URL:** <https://discourse.slicer.org/t/set-minimum-view-width-height-in-a-layout/16467>\
**Category:** Development\
**Created:** [March 10, 2021, 11:50am UTC](https://discourse.slicer.org/t/set-minimum-view-width-height-in-a-layout/16467 "2021-03-10T11:50:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [March 10, 2021, 11:50am UTC](https://discourse.slicer.org/t/set-minimum-view-width-height-in-a-layout/16467/1 "2021-03-10T11:50:56Z")

</div>

Hi everyone,  
I am trying to implement a custom layout very similar to SlicerLayoutFourUpQuantitativeView.  
However, I would like to set a minimum width/height to views so that when the user stretches one views others do not disappear.  
Is there already something existing to do that ?

Thanks in advance,  
Cheers

Pierre

---

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [March 10, 2021, 3:22pm UTC](https://discourse.slicer.org/t/set-minimum-view-width-height-in-a-layout/16467/2 "2021-03-10T15:22:50Z")

</div>

Probably not possible as of now

> [@Slice widget size in custom layouts](https://discourse.slicer.org/t/slice-widget-size-in-custom-layouts/2406):
>
> [custom-layout]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 format…

---

<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:** [March 10, 2021, 3:46pm UTC](https://discourse.slicer.org/t/set-minimum-view-width-height-in-a-layout/16467/3 "2021-03-10T15:46:40Z")

</div>

The proper solution would be to add attributes for this in CTK (in [ctkLayoutManager](https://github.com/commontk/CTK/blob/master/Libs/Widgets/ctkLayoutManager.cpp#L431)). But if you have never used C++ then you can work around this in Python by looking up the widget using [`slicer.util.findChildren`](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.findChildren) and adjusting sizing properties.

---

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [March 10, 2021, 4:40pm UTC](https://discourse.slicer.org/t/set-minimum-view-width-height-in-a-layout/16467/4 "2021-03-10T16:40:08Z")

</div>

Thanks Andras,  
Do you know if there is a way to fix the size at layout creation  
I tried to use verticalStretch="0" horizontalStretch="0" but it was not working

> \<item splitSize="300"\>"  
> " \<view class="vtkMRMLViewNode" singletontag="1" verticalStretch="0" horizontalStretch="0"\>"  
> " \<property name="viewlabel" action="default"\>1"

---

<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:** [March 11, 2021, 4:09am UTC](https://discourse.slicer.org/t/set-minimum-view-width-height-in-a-layout/16467/5 "2021-03-11T04:09:52Z")

</div>

There are no such properties implemented in [ctkLayoutManager](https://github.com/commontk/CTK/blob/master/Libs/Widgets/ctkLayoutManager.cpp) as `verticalStretch` and `horizontalStretch`. You can search for `.attribute` in the file to see what properties are available. You can modify this file to add support for more attributes.

---

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [March 11, 2021, 8:43am UTC](https://discourse.slicer.org/t/set-minimum-view-width-height-in-a-layout/16467/6 "2021-03-11T08:43:56Z")

</div>

This is probably a small issue but in [Slicer/vtkMRMLLayoutLogic.cxx at 81ff76b24d4913dbd992b7eed4d77805f306ffe8 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/blob/81ff76b24d4913dbd992b7eed4d77805f306ffe8/Libs/MRML/Logic/vtkMRMLLayoutLogic.cxx#L54), verticalStretch is defined
