python - 在 Maya 中使用图标填充窗口并根据窗口大小动态调整
问题描述
我想在 Maya 中创建一个窗口,其中填充了来自特定路径的图标。我知道该怎么做,但我也希望图标在我更改窗口大小时动态调整。例如,假设我有这个: 在此处输入图像描述
我想在调整大小时得到这个: 在此处输入图像描述
这是我的一些代码:
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
你也可以用谷歌pyqt flow layout
搜索那些已经用 Python 编写的。
推荐阅读
- blazor - Blazor - 多次创建子组件 - 当 EditForm.Model 更改时
- php - 使用实时搜索栏向 mysql 输入表单以输入外键
- python - 如何将字符串中包含数组的numpy字符串数组转换为字符串数组?
- c++ - 将指针数组的元素设置为 C++ 中的指针
- javascript - 将初始计数值设置为动态行表
- r - 有没有办法将它从上一时期特定于 R 中相同观察的值分配给变量?
- typescript - 在 Typescript 3.9 中使用两个依赖类型参数索引嵌套对象失败
- java - java 类和“import com.google.gson.*”错误
- c - rename() 如何在 C 的引擎盖下实际工作?
- c# - Windows 将多个控件合二为一