0

我开始尝试使用 Maya python,并且正在尝试做一些 UI。我遇到了一个非常奇怪的问题,我无法让按钮留在窗口的中心。我尝试了不同的方法,但似乎没有任何效果,代码如下:

import maya.cmds as cmds
cmds.window( width=200 )
WS = mc.workspaceControl("dockName", retain = False, floating = True,mw=80)

submit_widget = cmds.rowLayout(numberOfColumns=1, p=WS)

cmds.button( label='Submit Job',width=130,align='center', p=submit_widget)

cmds.showWindow()

这是一个简单的版本,但我仍然无法让它工作。有人能帮我吗?

4

1 回答 1

0

老实说,我不知道答案,因为每当我不得不深入研究 Maya 的原生 UI 内容时,它都会让我质疑自己的生活。

所以我知道这不完全是你所要求的,但我会选择这个:PySide改用。乍一看,它可能会让你觉得“哇,这太难了”,但它也好一百万倍(实际上更容易)。它更强大、更灵活、有很好的文档,并且还可以在 Maya 之外使用(因此学习起来非常有用)。Maya 自己的界面使用相同的框架,因此您甚至可以在对它PySide更熟悉后对其进行编辑。

这是在窗口中创建居中按钮的简单示例:

# Import PySide libraries.
from PySide2 import QtCore
from PySide2 import QtWidgets


class MyWindow(QtWidgets.QWidget):  # Create a class for our window, which inherits from `QWidget`
    
    def __init__(self, parent=None):  # The class's constructor.
        super(MyWindow, self).__init__(parent)  # Initialize its `QWidget` constructor method.
        
        self.my_button = QtWidgets.QPushButton("My button!")  # Create a button!
        
        self.my_layout = QtWidgets.QVBoxLayout()  # Create a vertical layout!
        self.my_layout.setAlignment(QtCore.Qt.AlignCenter)  # Center the horizontal alignment.
        self.my_layout.addWidget(self.my_button)  # Add the button to the layout.
        self.setLayout(self.my_layout)  # Make the window use this layout.
        
        self.resize(300, 300)  # Resize the window so it's not tiny.


my_window_instance = MyWindow()  # Create an instance of our window class.
my_window_instance.show()  # Show it!

还不错吧?

于 2020-08-17T16:52:56.603 回答