AREA forums upgrade
Read more about the planned upgrade of our forums
  • 1/3
You are here: Forum Home / Autodesk® Maya® / Python / PyQt and Maya. PyQt window parented to Maya Window?
IMPORTANT ANNOUNCEMENT ABOUT AREA FORUMS
  RSS 2.0 ATOM  

PyQt and Maya. PyQt window parented to Maya Window?
Rate this thread
 
39880
 
Permlink of this thread  
avatar
  • rstebbing
  • Posted: 17 February 2010 05:12 AM
  • Total Posts: 2
  • Joined: 22 August 2006 11:44 AM

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__(selfparent=None):
        
super(Formself).__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.lineeditSIGNAL("returnPressed()"),
        
self.updateUi)
        self
.setWindowTitle("Calculate")
        
    def updateUi(self)
:
        try:
            
text unicode(self.lineedit.text())
            self
.browser.append("%s = <b>%s</b>" (texteval(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()


Replies: 0
avatar

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__(selfparent=None):
        
super(Formself).__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()


Replies: 0
avatar

Thanks , its fixed my problem too ..



Replies: 0
avatar
  • sauzer
  • Posted: 09 November 2010 06:39 AM

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



Replies: 0
avatar
  • Bob_Gneu
  • Posted: 28 December 2010 06:26 AM

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



Replies: 0