使用图标在 Maya 中填充 window 并根据 window 大小动态调整
Populate window in Maya with icons and dynamically adjust depending on window size
我想在 Maya 中创建一个 window,其中填充了来自特定路径的图标。我知道该怎么做,但我还希望图标在我更改 window 的大小时动态调整。
例如,假设我有这个:
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()
如有任何帮助,我们将不胜感激
您需要的是所谓的 Flow 布局,其中布局内的项目会在调整小部件大小时自动调整自身。
这是 Qt 文档中的一个示例,您可以将其完全转换为 Python:
https://doc.qt.io/qt-4.8/qt-layouts-flowlayout-flowlayout-cpp.html
你也可以 google pyqt flow layout
对于已经写在 Python 中的那些。
我想在 Maya 中创建一个 window,其中填充了来自特定路径的图标。我知道该怎么做,但我还希望图标在我更改 window 的大小时动态调整。 例如,假设我有这个: 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()
如有任何帮助,我们将不胜感激
您需要的是所谓的 Flow 布局,其中布局内的项目会在调整小部件大小时自动调整自身。
这是 Qt 文档中的一个示例,您可以将其完全转换为 Python:
https://doc.qt.io/qt-4.8/qt-layouts-flowlayout-flowlayout-cpp.html
你也可以 google pyqt flow layout
对于已经写在 Python 中的那些。