为了账号安全,请及时绑定邮箱和手机立即绑定

Maya Python:按钮始终位于窗口的中央

Maya Python:按钮始终位于窗口的中央

杨魅力 2023-05-23 14:35:16
我开始尝试使用 Maya python,并且正在尝试做一些 UI。我遇到了一个非常奇怪的问题,我无法让按钮停留在窗口的中央。我尝试了不同的东西,但似乎没有任何效果,这是代码:import maya.cmds as cmdscmds.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()这是一个简单的版本,但我仍然无法正常工作。有人能帮我吗?
查看完整描述

1 回答

?
偶然的你

TA贡献1841条经验 获得超3个赞

老实说,我不知道答案,因为每当我不得不深入研究 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!

还不错,对吧?


查看完整回答
反对 回复 2023-05-23
  • 1 回答
  • 0 关注
  • 88 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信