我试图在Maya中获得一些PySide2的基础知识,现在我正面临着问题,按钮没有得到我想要的translateButtonX.setStyleSheet(...),它只是忽略了它。我试着调试它,并注意到,如果我设置window.setStyleSheet(...)而不是从图像,例如从颜色rgb,然后一切工作。有人知道我错过了什么吗?
import maya.cmds as cmds
from PySide2 import QtCore
from PySide2 import QtGui
from PySide2 import QtWidgets
import maya.OpenMayaUI as omui
try:
from shiboken import wrapInstance
except:
from shiboken2 import wrapInstance
def getMayaWindow():
pointer = omui.MQtUtil.mainWindow()
if pointer is not None:
return wrapInstance(long(pointer), QWidget)
######################################################################
def constraintMaster_UI():
objectName = 'PyConstraintMasterWin'
#check if ui already exists or not
if cmds.window('PyConstraintMasterWin', exists=1):
cmds.deleteUI('PyConstraintMasterWin',wnd=1)
#create window#
parent = getMayaWindow()
window = QtWidgets.QMainWindow(parent)
window.setObjectName(objectName)
window.setWindowTitle('Constraint Master')
#create main widget#
mainWidget = QWidget()
window.setCentralWidget(mainWidget)
QtWidgets.QStyleFactory.create('Windows')
#Create main vertical layout#
verticalLayout = QtWidgets.QVBoxLayout(mainWidget)
imagePath = cmds.internalVar(upd=1) + 'icons/test.png'
window.setStyleSheet('background-image:url(' + imagePath +
');border:solid black 1px;')
#create the translate layout#
translateLayout = QtWidgets.QHBoxLayout()
verticalLayout.addLayout(translateLayout)
#create translate label#
translateLabel = QtWidgets.QLabel('Translate:')
translateLayout.addWidget(translateLabel)
translateButtonX = QtWidgets.QPushButton('X')
translateLayout.addWidget(translateButtonX)
translateButtonX.setStyleSheet('background-color:rgb(0, 210,
255);border:white 1px;')
#show the window
window.show()
constraintMaster_UI()诚挚的问候!
发布于 2019-01-14 18:26:39
尝试了一个最小的示例,颜色和图像都正常工作。也许因为它是一个Maya插件,图像的路径不存在,尝试获取绝对路径,以便您确定:
imagePath = os.path.abspath(cmds.internalVar(upd=1) + 'icons/test.png')那么您就不会关心插件是否从不同的目录中执行。
https://stackoverflow.com/questions/49599888
复制相似问题