Dockable qtWidgets

Hello,
Is it possible to allow floating qtWidget UI to dock into the 3D Slicer interface?
I notice that every item in the Slicer interface can be dragged & dropped into panels around the viewport.
Is it possible for me to use the same base same class as the ‘Error Log’ or ‘Python Console’ window, which both dock and display ‘undock’ and ‘close’ buttons when docked?
Dockable

window = qt.QWidget()
window.setWindowTitle('Hello World')
window.show()

Nevermind, ChatGPT help me solve it:

from __main__ import qt, slicer

# Create a dockable widget
dockWidget = qt.QDockWidget()
dockWidget.setWindowTitle("Hello Dock")
dockWidget.setFeatures(qt.QDockWidget.DockWidgetClosable | qt.QDockWidget.DockWidgetFloatable | qt.QDockWidget.DockWidgetMovable)

# Create a simple widget to put inside the dockable widget
mainWidget = qt.QWidget(dockWidget)
layout = qt.QVBoxLayout(mainWidget)
button = qt.QPushButton("Click me", mainWidget)
layout.addWidget(button)
mainWidget.setLayout(layout)

dockWidget.setWidget(mainWidget)

# Add the dockable widget to the main window
slicer.util.mainWindow().addDockWidget(qt.Qt.LeftDockWidgetArea, dockWidget)
2 Likes

Thanks for posting the solution!