Pop-up ToolBox to the front

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

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) or add a custom toolbar (as it is done in Sequences module). You can make both docking widgets and toolbars float over the GUI or dock any side of the application window.

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’

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). You may also be able to change the class by changing the .ui file in a text editor.

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

Thanks very much @lassoan

1 Like

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.

1 Like