PySide Window Parented to Motionbuilder Main Window
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Motionbuilder documents a way to put a QWidget into a native Motionbuilder widget holder. This works, but has issues that I would rather not go into at the moment.
Another way to build PySide windows is by parenting a QMainWindow or QDialog to motionbuilder’s main Qt window. The code below shows how. Everything seems to work ok except for the fact that once the PySide window is shown, the user can’t select objects in the viewport until he right clicks in the view port first (or selects a menu and cancels).
Anyone know a way around this?
import sys from PySide import QtCore, QtGui class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.resize(200, 100) QtCore.QMetaObject.connectSlotsByName(Dialog) class ControlMainWindow(QtGui.QDialog): def __init__(self, parent=None): super(ControlMainWindow, self).__init__(parent) self.ui = Ui_Dialog() self.ui.setupUi(self) def _get_dialog_parent(): """ Find the main Motionbuilder window/QWidget. This will be used as the parent for all dialogs created by show_modal or show_dialog :returns: QWidget if found or None if not """ from PySide import QtGui # get all top level windows: top_level_windows = QtGui.QApplication.topLevelWidgets() # from this list, find the main application window. for w in top_level_windows: if (type(w) == QtGui.QWidget # window is always QWidget and len(w.windowTitle()) > 0 # window always has a title/caption and w.parentWidget() == None): # parent widget is always None return w return None mobu_main_window = _get_dialog_parent() tool_window = ControlMainWindow(mobu_main_window) tool_window.show()
Cheers,
Paul
Link copied