【问题标题】:How to add Icon to the window in maya using python如何使用python将图标添加到maya中的窗口
【发布时间】:2018-01-13 05:35:05
【问题描述】:

代码:

import maya.cmds as cmd

cmd.window(title='GUI')

cmd.showWindow()

这段代码创建了一个带有标题的窗口,我也想添加图标。谁能告诉我怎么做?

【问题讨论】:

  • 您想在窗口的哪个位置添加图标?概念草图/线框图会有所帮助。
  • 您可以使用 maya api 并使用 wrapinstance()
  • @python_fan 你有机会检查我的答案吗?

标签: python user-interface maya


【解决方案1】:

您不能直接更改图标。但是,如果您可以访问底层 Qt 小部件,则可以更改它。

import maya.cmds as cmds
from maya import OpenMayaUI as omui

# Special cases for different Maya versions
try:
    from shiboken2 import wrapInstance
except ImportError:
    from shiboken import wrapInstance

try:
    from PySide2.QtGui import QIcon
    from PySide2.QtWidgets import QWidget
except ImportError:
    from PySide.QtGui import QIcon, QWidget

# Create a window and save its name    
window = cmds.window(title='GUI')

# Show the newly created window
cmds.showWindow(window)

# Get a pointer and convert it to Qt Widget object
qw = omui.MQtUtil.findWindow(window)
widget = wrapInstance(long(qw), QWidget)

# Create a QIcon object
icon = QIcon('/path/to/icon.png')

# Assign the icon
widget.setWindowIcon(icon)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 2021-03-06
    • 1970-01-01
    • 2013-01-25
    相关资源
    最近更新 更多