# Pop-up ToolBox to the front

**URL:** <https://discourse.slicer.org/t/pop-up-toolbox-to-the-front/9709>\
**Category:** Support\
**Created:** [January 4, 2020, 4:57pm UTC](https://discourse.slicer.org/t/pop-up-toolbox-to-the-front/9709 "2020-01-04T16:57:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [January 4, 2020, 4:57pm UTC](https://discourse.slicer.org/t/pop-up-toolbox-to-the-front/9709/1 "2020-01-04T16:57:51Z")

</div>

I want to make a pop-up toolbox to show/hide it with a button in main window

> self.ToolBoxCheck = qt.QCheckBox(‘Show ToolBox’)  
> self.ToolBoxCheck.connect(‘clicked(bool)’, self.ShowToolBox)  
> Layout.addRow(self.ToolBoxCheck)  
> self.ToolBox\_widget = slicer.util.loadUI(“E:/MyExtension/Resources/UI/ToolBox.ui”)  
> self.Button\_widget = self.ToolBox\_widget .findChild(qt.QPushButton, ‘Button1’)

CheckBox works perfect launching widget window but I don´t know how to make it always on top.

Thanks

---

<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:** [January 4, 2020, 5:32pm UTC](https://discourse.slicer.org/t/pop-up-toolbox-to-the-front/9709/2 "2020-01-04T17:32:40Z")

</div>

While it might be possible to keep a widget always on top, the proper solution would be to place it in the application window’s layout: a docking window (as it is done in [NodeInfo module](https://github.com/SlicerRt/SlicerDebuggingTools/blob/master/NodeInfo/NodeInfo.py)) or add a custom toolbar (as it is done in [Sequences module](https://github.com/SlicerRt/Sequences/blob/master/SequenceBrowser/qSlicerSequenceBrowserModule.cxx)). You can make both docking widgets and toolbars float over the GUI or dock any side of the application window.

---

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [January 4, 2020, 7:20pm UTC](https://discourse.slicer.org/t/pop-up-toolbox-to-the-front/9709/3 "2020-01-04T19:20:59Z")

</div>

Ok. I have a DockWidget working as you propose in NodeInfo module example and it´s really cool.  
I have turn my ToolBar to a DockWidget in Qt Designer. How can i use it?  
It throw me this error:

> .setFeatures(qt.QDockWidget.DockWidgetClosable + qt.QDockWidget.DockWidgetMovable + qt.QDockWidget.DockWidgetFloatable)  
> AttributeError: QFrame has no attribute named ‘setFeatures’

---

<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:** [January 5, 2020, 3:47am UTC](https://discourse.slicer.org/t/pop-up-toolbox-to-the-front/9709/4 "2020-01-05T03:47:20Z")

</div>

The easiest way to change the base class of the top-level widget in Qt Designer is to create a new widget and copy-paste its content (see [here](https://forum.qt.io/topic/20723/how-to-change-my-gui-base-class-qwidget-qmainwindow/14)). You may also be able to change the class by changing the .ui file in a text editor.

---

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [January 5, 2020, 3:10pm UTC](https://discourse.slicer.org/t/pop-up-toolbox-to-the-front/9709/5 "2020-01-05T15:10:20Z")

</div>

Ok. I go around it and it´s working. I send my config in case someone had same need.

CheckButton to show/hide ToolBox:

> self.ToolBoxCheck = qt.QCheckBox(‘Show ToolBox’)  
> self.ToolBoxCheck.connect(‘clicked(bool)’, self.ShowToolBox)  
> Layout.addRow(self.ToolBoxCheck)

> def ShowToolBox(self, pressed):  
> if pressed:  
> self.ToolBox\_widget.show()  
> else:  
> self.ToolBox\_widget.hide()

Add ToolBox Widget to Layout:

> self.ToolBox\_widget = slicer.util.loadUI(“E:/MyExtension/Resources/UI/ToolBox.ui”)  
> self.Button\_widget = self.ToolBox\_widget.findChild(qt.QPushButton, ‘Button1’)  
> mainWindow = slicer.util.mainWindow()  
> mainWindow.addDockWidget(qt.Qt.RightDockWidgetArea, self.ToolBox\_widget)

QtWidget has this structure:

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

Thanks very much @lassoan

---

<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:** [January 5, 2020, 3:19pm UTC](https://discourse.slicer.org/t/pop-up-toolbox-to-the-front/9709/6 "2020-01-05T15:19:14Z")

</div>

It’s great that you could make this work for you. Just one more recommendation: instead of using findChild for each button, you can automatically get all of them at once by calling [`slicer.util. childWidgetVariables`](https://github.com/Slicer/Slicer/blob/b6bf2d30c99f731644182f750a4abd8e3c8204ca/Base/Python/slicer/util.py#L299).
