# How to handle the resize event of mainwindow

**URL:** <https://discourse.slicer.org/t/how-to-handle-the-resize-event-of-mainwindow/19072>\
**Category:** Development\
**Tags:** python\
**Created:** [August 5, 2021, 8:38am UTC](https://discourse.slicer.org/t/how-to-handle-the-resize-event-of-mainwindow/19072 "2021-08-05T08:38:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wycstar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/wycstar/32/11800_2.png) [@wycstar](https://discourse.slicer.org/u/wycstar)\
**Post date:** [August 5, 2021, 8:38am UTC](https://discourse.slicer.org/t/how-to-handle-the-resize-event-of-mainwindow/19072/1 "2021-08-05T08:38:49Z")

</div>

hi all, i added a new widget to the top toolbar of the slicer mainwindow, now i wish it have a maximum width equal to the width of the main window, no matter how i resize the mainwindow. what i want to do is handle the resize event of the mainwindow, and set the width of the widget in the event handler, any better ideas to implement this?

---

<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:** [August 5, 2021, 11:09am UTC](https://discourse.slicer.org/t/how-to-handle-the-resize-event-of-mainwindow/19072/2 "2021-08-05T11:09:03Z")

</div>

Seems like you want to use standard Qt size policy stuff to set the horizontal policy to be expanding.

[https://doc.qt.io/qt-5/qsizepolicy.html#Policy-enum](https://doc.qt.io/qt-5/qsizepolicy.html#Policy-enum)
