How to refresh Maya cmds.gridLayout?

Viewed 180

Maya cmds: I have a basic grid and I want to remove an item, but the grid doesn't update. So the removed item keeps taking up space. How can I make the gridLayout refresh or re-align its items?

import maya.cmds as cmds

def change(*args):
    cmds.iconTextCheckBox('two', edit=True, visible=False)

window = cmds.window()
cmds.gridLayout()

cmds.iconTextCheckBox('one', style='textOnly', label='item')
cmds.iconTextCheckBox('two', style='textOnly', label='item')
cmds.iconTextCheckBox('three', style='textOnly', label='item')

cmds.button(label='GO', command=change)
cmds.showWindow(window)
1 Answers

Executing your code you don't delete the second element, you're just turning its visibility off.

enter image description here

To check this statement, execute the following line of code and you'll turn a visibility on:

cmds.iconTextCheckBox('two', edit=True, visible=True)

enter image description here

Solution

You need to use QT's QGridLayout() class (not Maya's cmds). To remove a widget from a layout, call removeWidget() method.

Related