首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maya2018 Python+QT:查询导入TextField的值

Maya2018 Python+QT:查询导入TextField的值
EN

Stack Overflow用户
提问于 2017-12-28 21:16:10
回答 1查看 503关注 0票数 1

我一直在跟踪本教程,在Maya插件中使用来自QT设计器的.UI文件。它指出,为了在UI加载到Maya之后查询QtextEdit字段的值,我需要执行以下操作:

因此,现在当我们在maya中加载QT时,我们可以通过使用以下代码行来查询行文本,每次我们想编辑文本时都可以编辑: pm.textField('textFieldName', query = True, text = True)

然而,我似乎无法使它发挥作用。我按如下方式加载UI:

代码语言:javascript
复制
# Load our window and put it into a variable.
ebWin = cmds.loadUI(uiFile = self.BE_UIpath)

没有问题,当我尝试cmds.showWindow(ebWin)时,一切都正常工作,看起来与预期完全一致。现在,当我试图查询我命名为“exportDirectoryTF”的QtextEdit时,玛雅坚称它并不存在。我尝试过两种不同的方法:

办法A:

代码语言:javascript
复制
# Connect Functions to the buttons.
exportDir = ebWin.textField('exportDirectoryTF', query = True, text = True)

其中产出:

代码语言:javascript
复制
# 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:

代码语言:javascript
复制
import maya.cmds as cmds
# Connect Functions to the buttons.
exportDir = cmds.textField('exportDirectoryTF', query = True, text = True)

返回:

代码语言:javascript
复制
# 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命令时的变量,还是两者都没有。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-29 11:42:22

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

代码语言:javascript
复制
ui = "D:/temp/test.ui"
qtW = cmds.loadUI(uiFile = ui)
cmds.showWindow(qtW)
cmds.textField("lineEdit", query=True, text=True)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48014493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档