PySide Window Parented to Motionbuilder Main Window

robotProdigy
Advocate
Advocate

PySide Window Parented to Motionbuilder Main Window

robotProdigy
Advocate
Advocate

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

Reply
4,395 Views
3 Replies
Replies (3)

ThomasGryphon
Contributor
Contributor

necro-posting out of morbid curiosity as it seems odd that this has never been solved...

0 Likes

morten_bohne
Advocate
Advocate

The issue still occurs with PySide2 in Motionbuilder19 😞

0 Likes

Anonymous
Not applicable

This only happen if you launch your tool from the python IDE, if you wrap your tool in a menu it should be fine.  Also it also depends on which type of widget is in UI, Qbutton won't cause this where as a QComboBox will always do it.

 

Again this doesn't happen if you launch from the menu 🙂

0 Likes