在Maya中使用图标填充窗口,并根据窗口大小动态调整

时间:2018-08-16 02:01:48

标签: python user-interface maya

我想在Maya中创建一个窗口,其中填充了来自特定路径的图标。我知道该怎么做,但是我还希望图标在更改窗口大小时动态调整。 例如,假设我有这个: enter image description here

,我想在调整大小时得到以下信息: enter image description here

这是我的一些代码:

import maya.cmds as cmds
import os
from os import listdir

def UI(*args):

    if cmds.window("Test", exists = True):
        cmds.deleteUI("Test")
    testwindow = cmds.window("Test", t="Test Window", sizeable = 1)

    cmds.scrollLayout('srcoll', p = "Test")
    cmds.rowColumnLayout("ColLayout", p = "Test", nc = 3)#I imagine the "nc" command is probably useless here, I am just leaving it for testing purposes

    cmds.showWindow("Test")

customPath = "C:\Users\$username$\Desktop"
customPathItems = listdir(customPath)


def popUI(*args):
    for item in customPathItems:
        if item.endswith("_icon.png"):
            cmds.iconTextButton(l = item, p = "ColLayout", i = customPath + "/" + item, w = 128, h = 128)


def buildUI(*args):
    UI()    
    popUI()     

buildUI()

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

您所需要的称为流布局,该布局中的项目在调整窗口小部件的大小时会自动进行调整。

这是Qt文档中的一个示例,您可以将其完全转换为Python:

https://doc.qt.io/qt-4.8/qt-layouts-flowlayout-flowlayout-cpp.html

您也可以在pyqt flow layout上搜索已经用Python编写的内容。