我一直在跟踪本教程,在Maya插件中使用来自QT设计器的.UI文件。它指出,为了在UI加载到Maya之后查询QtextEdit字段的值,我需要执行以下操作:
因此,现在当我们在maya中加载QT时,我们可以通过使用以下代码行来查询行文本,每次我们想编辑文本时都可以编辑:
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时,玛雅坚称它并不存在。我尝试过两种不同的方法:
办法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命令时的变量,还是两者都没有。
如果有人能为我指出正确的方向,我们将不胜感激。
发布于 2017-12-29 11:42:22
从您的代码中,在尝试执行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)https://stackoverflow.com/questions/48014493
复制相似问题