# Modify properties of the segment editor (maximumHeight of ctkExpandableWidget)

**URL:** <https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [July 8, 2019, 5:23pm UTC](https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467 "2019-07-08T17:23:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricM](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@EricM](https://discourse.slicer.org/u/EricM)\
**Post date:** [July 8, 2019, 5:23pm UTC](https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467/1 "2019-07-08T17:23:58Z")

</div>

Hello,

I am a beginner at Slicer (1 week today), so I apologize if my question is simple. I am building a small module in which I would like to include the Segment Editor. In particular, I would like to set the maximum height of the ctkExpandableWidget object (i.e., the list of the segmentations) so as not to make it too long.

The following does what I want when executed in the Python console

```
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.show()
segmentEditorWidget.layout().itemAt(2).widget().setMaximumHeight(100)

```

#or this  
segmentEditorWidget.children()[13].setMaximumHeight(100)

However, when I put the same code in my .py file and insert it into my module, the ctkExpandableWidget object still behaves like the default ctkExpandableWidget (i.e., it can expand much further than this).

There is more code in my .py file (I followed a couple tutorials that also use the Segment Editor Widget in them), namely:

```
segmentationNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSegmentationNode')
segmentationNode.CreateDefaultDisplayNodes()

segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
slicer.mrmlScene.AddNode(segmentEditorNode)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)

#inserts into a QGroupBox
groupBoxSegmentation = qt.QGroupBox("Segmentation")
segmentationLayout = qt.QVBoxLayout()
segmentationLayout.addWidget(segmentEditorWidget)
groupBoxSegmentation.setLayout(segmentationLayout)

```

Perhaps there is code in here that is overwriting the maximumHeight that I am trying to force?

Thank you for your help, and any comments to improve the above code are welcome!  
EricM

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [July 8, 2019, 5:55pm UTC](https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467/2 "2019-07-08T17:55:44Z")

</div>

There’s an open issue related to layout sizing of the segment editor widget which is what you are describing. This work has stalled, but you might want to look into helping pick this back up.

See [https://github.com/Slicer/Slicer/pull/1085](https://github.com/Slicer/Slicer/pull/1085)

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [July 8, 2019, 6:09pm UTC](https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467/3 "2019-07-08T18:09:54Z")

</div>

Also, in general I’d advise against using pixel values for setting sizes because the wide range of DPIs of the current screens. Use ratios, or multiples of the sizeHint that you can get from certain elements.

---

<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 9, 2019, 4:09am UTC](https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467/4 "2019-07-09T04:09:25Z")

</div>

> [@cpinter](#):
>
> in general I’d advise against using pixel values for setting sizes because the wide range of DPIs of the current screens. Use ratios, or multiples of the sizeHint that you can get from certain elements.

Qt5 can scale sizes specified in pixels (they are now called “device independent pixels”) - see [High DPI Displays | Qt 5.15](https://doc.qt.io/qt-5/highdpi.html). So, in theory, specifying size simply in pixels may work well on a variety of displays and resolutions.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [July 9, 2019, 2:02pm UTC](https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467/5 "2019-07-09T14:02:05Z")

</div>

Hm. I kind of liked using size hints for sizing because it allowed to be very precise compared to UI elements in whatever style. So you say we can now use pixels again in Slicer core too? I think we moved away from that completely.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [July 9, 2019, 5:06pm UTC](https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467/6 "2019-07-09T17:06:41Z")

</div>

I’d also vote for hints and ratios - I think those device independent pixels sound error prone.

---

<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 10, 2019, 3:36am UTC](https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467/7 "2019-07-10T03:36:00Z")

</div>

When you use the Qt designer then most sizes and size hints are defined in device-independent pixels. With the automatic pixel scaling, simple layouts often work well enough. I would try to stick to these simple layouts whenever it is possible.

If there are complicated UI mechanisms or fine-tuned layout behavior is needed then of course it makes sense compute sizes from ratios, font sizes, or other metrics.

---

<div class="post-metadata">

**Author:** ![EricM](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@EricM](https://discourse.slicer.org/u/EricM)\
**Post date:** [July 12, 2019, 7:47am UTC](https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467/8 "2019-07-12T07:47:07Z")

</div>

Thanks for these tips.  
@jamesobutler - I will look at the link you provided from @Johan_Andruejol.  
@Johan_Andruejol - is the [SegmentEditorUIFix.zip](https://github.com/Slicer/Slicer/files/2814355/SegmentEditorUIFix.zip) file you provided in this [link](https://github.com/Slicer/Slicer/pull/1085) after the modifications on Jan 31, or is it from the original post on Jan 30? If it is after the second round of modifications, I can try to see if it fits in my module better.

Thanks again,  
Eric

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [July 12, 2019, 7:58am UTC](https://discourse.slicer.org/t/modify-properties-of-the-segment-editor-maximumheight-of-ctkexpandablewidget/7467/9 "2019-07-12T07:58:05Z")

</div>

The archive provided by @Johan_Andruejol contains small files created on Jan 25 and useful only to test the changes proposed in the associated PR [https://github.com/Slicer/Slicer/pull/1085](https://github.com/Slicer/Slicer/pull/1085)
