|
|
|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
|
Autodesk® Entertainment Creation Suite Ultimate®
|
| PyQt and Maya. PyQt window parented to Maya Window?
|
|
|
I’d like to find a way to parent a PyQt window to the main Maya window.
Visually the goal is to add code to a script like the one below so that the window will not get buried behind the main Maya window if it loses focus. For example the Maya Python/Mel Script Editor always stays on top of the Main Maya window even when the main Maya window has focus as long as they overlap. In contrast the pyQT test script below will go behind the main Maya window. Any thoughts on how to fix this? Failed explorations so far include adding this near the top of the script:
import maya.OpenMayaUI as omu
And then right after the class definition ends grabbing the handle to the main Maya window with a line like this:
hndl = int(omu.M3dView().applicationShell())
If these explorations are headed in the correct direction my thought was to parent the “form” to the hndl when it is first called but this doesn’t seem to work.
Current behavior: script doesn’t crash and works as designed.
Expected behavior: script doesn’t crash and works as designed and stays on top of the main Maya window when the 2 windows overlap even when it doesn’t have focus.
Any ideas?
# Body of the code below adapted from the book 'Rapid GUI Programming with Python and QT' by Summerfield
from __future__ import division
import sys
sys.path.append('C:/Python26/Lib/site-packages')
sys.path.append('C:/Program Files/Autodesk/Maya2010/devkit/other/PyQtScripts/qt')
import pumpThread as pt
import maya.OpenMayaUI as omu
from PyQt4.QtWinMigrate import QWinWidget
from math import * from PyQt4.QtCore import * import PyQt4.QtGui as QtGui
class Form(QtGui.QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.browser = QtGui.QTextBrowser()
self.lineedit = QtGui.QLineEdit("Type an expression and press Enter")
self.lineedit.selectAll()
layout = QtGui.QVBoxLayout()
layout.addWidget(self.browser)
layout.addWidget(self.lineedit)
self.setLayout(layout)
self.lineedit.setFocus()
self.connect(self.lineedit, SIGNAL("returnPressed()"),
self.updateUi)
self.setWindowTitle("Calculate")
def updateUi(self):
try:
text = unicode(self.lineedit.text())
self.browser.append("%s = <b>%s</b>" % (text, eval(text)))
except:
self.browser.append("<font color=red>%s is invalid!</font>" % text)
hndl = int(omu.M3dView().applicationShell()) global app global form
pt.initializePumpThread()
app=QtGui.qApp global core
core = QWinWidget(hndl)
form = Form(core)
form.show()
|
|
|
|
I also tried same thing and here is sample code to
parent pyQt window to Maya window.
It’s working fine.
And, we don’t need pumpThread anymore.
Gaki
import sip
import maya.OpenMayaUI as mui
from PyQt4.QtCore import * from PyQt4.QtQtGui import *
def getMayaWindow():
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QObject)
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.WindowTitle('Test Dialog')
self.setObjectName('mainUI')
self.mainLayout = QVBoxLayout(self)
self.myButton = QPushButton('myButton')
self.mainLayout.addWidget(self.myButton)
global app global form
app = qApp
form = Form(getMayaWindow())
form.show()
|
|
|
|
Thanks , its fixed my problem too ..
|
|
|
|
Is this true only for Maya 2011?
I am currently using Maya 2010 and this is the error message I get
AttributeError: ‘module’ object has no attribute ‘MQtUtil’
Thanks for the help
|
|
|
|
Qt was not added until maya 2011, this past year.
That module wont exist until you update to the new version.
http://area.autodesk.com/blogs/stevenr/maya_2011_highlight_qt_user_interface
|
|
|
|
|
|