如何将图标添加到 textScrollList

How add icon to textScrollList

是否可以将图标网格添加到 maya 中的 textScrollList 项目python?

def allMeshes(*args):
listMesh = cmd.ls(type="mesh")
geometry = cmd.listRelatives(listMesh, p=True )

if len(geometry) > 0:
    for g in geometry:
        cmd.textScrollList('lstMesh', e=True, a=g) #here add icon
else:
    return

谢谢

就像我在评论中所说的那样,我没有看到为该控件添加图标的方法,但这里是您如何使用 PySide Maya 自带的 PySide 使其工作的方法所以不需要安装任何东西。如果您使用的是 2017/2018,则它会改用 PySide2,并且需要进行非常小的更改。

from PySide import QtGui, QtCore
import maya.cmds as cmds


class Window(QtGui.QDialog):

    def __init__(self, parent=None):
        # Inherit QDialog.
        QtGui.QDialog.__init__(self, parent=parent)

        # Create a list.
        self.list = QtGui.QListWidget(parent=self)

        # Create a layout so the list will stretch with the window.
        self.main_layout = QtGui.QVBoxLayout()
        self.main_layout.addWidget(self.list)
        self.setLayout(self.main_layout)

        # Set window properties.
        self.setWindowTitle("My tool")
        self.resize(300, 500)

        # Populate list with all mesh objects.
        self.populate_list()

    def populate_list(self):
        # Collect all meshes in the scene.
        geometry = cmds.listRelatives(cmds.ls(type="mesh"), parent=True) or []

        # This uses Maya's internal icons.
        # You can just point it to whatever icon you want.
        img_name = cmds.resourceManager(nameFilter="*mesh*")[0]
        img_path = ":/{}".format(img)

        # Create list items.
        for obj in geometry:
            item = QtGui.QListWidgetItem(obj)
            item.setSizeHint(QtCore.QSize(0, 50)) # Increases item's height a bit.
            item.setIcon(QtGui.QIcon(img_path))
            self.list.addItem(item)


# Create an instance of the tool.
win = Window()
win.show()

这是场景中 3 个球体的结果: