Maya 2018 Python + QT:查询导入的TextField的值

问题描述 投票:1回答:1

我一直在关注This Tutorial在Maya插件中使用来自QT设计器的.UI文件。它声明,为了在UI加载到Maya之后查询QtextEdit字段的值,我需要执行以下操作:

所以现在当我们在maya中加载我们的QT Ui时,我们可以通过使用以下代码行来查询每次我们想要的行编辑文本:

pm.textField('textFieldName', query = True, text = True)

但是我似乎无法使其发挥作用。我正在加载UI如下:

# Load our window and put it into a variable.
ebWin = cmds.loadUI(uiFile = self.BE_UIpath)

没有问题,当我尝试cmds.showWindow(ebWin)时,一切正常并且看起来完全符合预期。现在,当我尝试查询我命名为'exportDirectoryTF'的QtextEdit时,Maya坚持认为它不存在。我尝试了两种不同的方法:

方法A:

# Connect Functions to the buttons.
exportDir = ebWin.textField('exportDirectoryTF', query = True, text = True)

哪个输出:

# Error: 'unicode' object has no attribute 'textField'
# # Traceback (most recent call last):
# #   File "C:/Users/Censored/Documents/maya/2018/plug-ins/EB_pi_cmds.py", line 39, in doIt
# #     exportDir = ebWin.textField('exportDirectoryTF', query = True, text = True)
# # AttributeError: 'unicode' object has no attribute 'textField'

和方法B:

import maya.cmds as cmds
# Connect Functions to the buttons.
exportDir = cmds.textField('exportDirectoryTF', query = True, text = True)

返回:

# RuntimeError: Object 'exportDirectoryTF' not found.
# # Traceback (most recent call last):
# #   File "C:/Users/Censored/Documents/maya/2018/plug-ins/EB_pi_cmds.py", line 39, in doIt
# #     exportDir = cmds.textField('exportDirectoryTF', query = True, text = True)
# # RuntimeError: Object 'exportDirectoryTF' not found. # 

本教程有'pm.textField('textFieldName',q = True,text = True)',我无法弄清楚“pm”的来源,是否应该指示加载UI的变量或maya Python textField命令,或两者都不。

如果有人能指出我在这里正确的方向,将不胜感激。

python qt textfield maya
1个回答
0
投票

从您的代码中,您尝试执行textField cmd时看不到它。以下代码对我来说很好。 test.ui只包含一个名为“lineEdit”的lineEdit字段的窗口小部件。查询文本字段仅在窗口可见时才有效。如果关闭窗口并尝试查询文本字段,则会出现“找不到对象”错误。

ui = "D:/temp/test.ui"
qtW = cmds.loadUI(uiFile = ui)
cmds.showWindow(qtW)
cmds.textField("lineEdit", query=True, text=True)
© www.soinside.com 2019 - 2024. All rights reserved.