# To add Widget on Slice Views

**URL:** <https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787>\
**Category:** Support\
**Tags:** python\
**Created:** [April 1, 2022, 4:44am UTC](https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787 "2022-04-01T04:44:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![joanne40226](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joanne40226/32/14681_2.png) [@joanne40226](https://discourse.slicer.org/u/joanne40226)\
**Post date:** [April 1, 2022, 4:44am UTC](https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787/1 "2022-04-01T04:44:21Z")

</div>

Hi, I am now working on placing my button group widget on the side of the Slice View.  
I did it by placing a toolButton on the sliceController.

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

However, the question here is that I want it place on the view forever, which means that I should not use a toolButton which will make my button list disappear as long as the toolButton is not triggered.  
I wish to add widget on the Slice View but I still cannot fix this problem, hope someone can help. Thank you.

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [April 1, 2022, 9:07am UTC](https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787/2 "2022-04-01T09:07:12Z")

</div>

The button of the sliceWidget that does not dissapear when is pinned it’s implemented with a ctkPopUpWidget [CTK/ctkPopupWidget.cpp at master · commontk/CTK · GitHub](https://github.com/commontk/CTK/blob/master/Libs/Widgets/ctkPopupWidget.cpp)

You can check if that is useful for you. I have used them for the exact purpose you describe

Hope this helps

---

<div class="post-metadata">

**Author:** ![joanne40226](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joanne40226/32/14681_2.png) [@joanne40226](https://discourse.slicer.org/u/joanne40226)\
**Post date:** [April 1, 2022, 10:14am UTC](https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787/4 "2022-04-01T10:14:24Z")

</div>

@mau_igna_06  
Hi, thank you for the quick reply!  
I did what you suggest, it works. However, I encountered a problem which the width of the popupWidget is to large and I could not fix it by now. Do you have any suggestion? Thank you so much.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/4/8460e8064f4f2ae5ab2f5ce3e18093c832c8056c.png)

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [April 1, 2022, 10:32am UTC](https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787/5 "2022-04-01T10:32:30Z")

</div>

I think the size of the popup is controlled by the widget that is inside it

---

<div class="post-metadata">

**Author:** ![joanne40226](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joanne40226/32/14681_2.png) [@joanne40226](https://discourse.slicer.org/u/joanne40226)\
**Post date:** [April 1, 2022, 10:34am UTC](https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787/6 "2022-04-01T10:34:17Z")

</div>

@mau_igna_06  
I did it by this way

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/7/97b49df5ce98d330e3b569e07e24cf0c53fc1ecb.png)  
So I think the horizontal size is fixed by the sliceController horizontal size?

---

<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:** [April 2, 2022, 1:34am UTC](https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787/7 "2022-04-02T01:34:00Z")

</div>

You have chosen the `qt.QVBoxLayout` = vertical box layout, which puts all widgets in a column. If you want to display widgets in a row you can use `qt.QHBoxLayout`.

---

<div class="post-metadata">

**Author:** ![joanne40226](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joanne40226/32/14681_2.png) [@joanne40226](https://discourse.slicer.org/u/joanne40226)\
**Post date:** [April 3, 2022, 2:39am UTC](https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787/8 "2022-04-03T02:39:34Z")

</div>

@lassoan Hello, Thanks for your reply.  
I did what you suggest and it looks great as the image below.

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

However, I still wish it to be a vertical button table. Which looks like  
the image below but with a narrow width

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/8/985efa796ce70e8eafdcf5a333c7cfcfe3a171b1.png)  
The problem is that as long as the popupWidget is added under the sliceController().layout(), the width will be as large as the slice Controller layout. Which I want the white blank to disappear as the above image shows.

---

<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:** [April 3, 2022, 2:25pm UTC](https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787/9 "2022-04-03T14:25:49Z")

</div>

If you want to get vertical button layout then I would recommend the solution that @ungi described above.

---

<div class="post-metadata">

**Author:** ![joanne40226](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joanne40226/32/14681_2.png) [@joanne40226](https://discourse.slicer.org/u/joanne40226)\
**Post date:** [April 4, 2022, 2:59am UTC](https://discourse.slicer.org/t/to-add-widget-on-slice-views/22787/10 "2022-04-04T02:59:42Z")

</div>

@lassoan I see, I will try it later.  
Thank you so much for the reply.
