Wrapper function to dock any QWidget subclass.
Difference
This fork differs from the original in that it doesn't embed your widgets in the layout provided by Maya's panel. Instead, it embeds your widget into the panel, which means it works with existing widgets and widgets that don't fit in a QLayout; like a QML component. It also addresses a few bugs; e.g. no references to non-existent variables (logger
) and no unused imports (QtGui
).
Usage
class Example(QtWidgets.QWidget):
label = "My example"
def __init__(self, parent=None):
super(Example, self).__init__(parent)
self.setWindowTitle(self.label)
layout = QtWidgets.QHBoxLayout(self)
layout.setContentsMargins(2, 2, 2, 2)
label = QtWidgets.QLabel("Hello World!")
layout.addWidget(label)
Regular instantiation of widget is..
example = Example()
To instantiate it in a docked panel..
example = Dock(Example)
The Dock
function is re-entrant; it will prevent multiple instances from overlapping each other, by deleting any existing dock of the same __name__
. An optional label
class-attribute may be added to control the appearence of the dock in the Maya UI.
Notes: depending on your use, Dock.py might need a few changes:
from Qt.QtCompat import wrapInstance
usefrom shiboken2 import wrapInstance
tested and working in Maya 2022 👍