PyQt4's QPixmap not showing on Maya 2013

145 views
Skip to first unread message

Salvador Olmos Miralles

unread,
Sep 19, 2013, 10:19:14 AM9/19/13
to python_in...@googlegroups.com
So I've made a window for Maya in QtDesigner, and I've tried assigning a label a pixmap from QtDesigner, from the python script that references de ui file, and still I can't get the pixmap to work. I've also change a thousand times the .jpg path and none of them work. I paste my Python script:


#----------------------------------------

from PyQt4 import QtGui, QtCore, uic
import platform, sys, random
import maya.cmds as cmds

os = platform.system()
if os == "Windows":
uiFile = 'path_to_ui'
else:
uiFile = 'path_to_ui'
form_class, base_class = uic.loadUiType(uiFile)

class textureReleaseUI(form_class, base_class):

def __init__(self, parent=mui.getMayaWindow()):
super(textureReleaseUI, self).__init__(parent)
self.setupUi( self )
self.initUI()
def initUI(self):
pixmap = QtGui.QPixmap("Y:\dev\python\mnmModelToolsHeader.jpg")
self.header.setPixmap(pixmap)
self.connectSignals()
def connectSignals(self):
self.connect(self.orient_btn, QtCore.SIGNAL('pressed()'), orientTip)
self.connect(self.clean_btn, QtCore.SIGNAL('pressed()'), main)
self.connect(self.rename_btn, QtCore.SIGNAL('pressed()'), checkNaming)
self.connect(self.none_btn, QtCore.SIGNAL('pressed()'), printLines)


def runUI():
#global app
global win
#app=QtGui.QApplication(sys.argv)
win = textureReleaseUI()
win.show()
#sys.exit(app.exec_())
runUI()

Jesse Kretschmer

unread,
Sep 19, 2013, 3:37:17 PM9/19/13
to python_in...@googlegroups.com
I assume that self.header is a QLabel. The UI file would be quite helpful for reference.

You should flip the slashes or if you really want backslashes, use the raw string notation by putting an r before the quotes:
r"Y:\dev\python\mnmModelToolsHeader.jpg"

Also, make sure that the file is found by python:
myFile = 
"Y:/dev/python/mnmModelToolsHeader.jpg"
if os.path.exists(myFile):
    print "yay"

It may well be possible that Qt is having an issue with your jpeg, so try loading a different image or a different format.

Tell me if any of these suggestions put you in the right direction.

Cheers,
jesse




--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To post to this group, send email to python_in...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Salvador Olmos Miralles

unread,
Sep 20, 2013, 5:11:36 AM9/20/13
to python_in...@googlegroups.com
I tried what you said and the path was right, I ended up fixing it deleting the QLabel and creating it from scratch in the .py file, Here I post the working script file:

class textureReleaseUI(form_class, base_class):

def __init__(self, parent=mui.getMayaWindow()):
super(textureReleaseUI, self).__init__(parent)
self.setupUi( self )
self.initUI()
def initUI(self):

self.header = QtGui.QLabel(self.centralwidget)
self.header.setGeometry(QtCore.QRect(0,-5,500,81))
self.header.setPixmap(QtGui.QPixmap('\mnmModelToolsHeader.jpg'))
self.header.setObjectName('header')
self.setCentralWidget(self.centralwidget)


self.connectSignals()
def connectSignals(self):
self.connect(self.orient_btn, QtCore.SIGNAL('pressed()'), orientTip)
self.connect(self.clean_btn, QtCore.SIGNAL('pressed()'), main)
self.connect(self.rename_btn, QtCore.SIGNAL('pressed()'), checkNaming)
self.connect(self.none_btn, QtCore.SIGNAL('pressed()'), printLines)

Thank you very much for the help!
Salvador

Reply all
Reply to author
Forward
0 new messages