0

试图在 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()

此致!

4

1 回答 1

0

尝试了一个最小的例子,颜色图像都有效。可能因为是 Maya 插件,所以图片的路径不存在,尝试获取绝对路径,这样就可以确定了:

imagePath = os.path.abspath(cmds.internalVar(upd=1) + 'icons/test.png')

那么您将不在乎插件是否从不同的目录执行。

于 2019-01-14T10:26:38.660 回答