In my ongoing quest to work with Qt to build UIs, I have a hard time figuring out how to read text from a QLineEdit. I built my interface with QtDesigner, added a QLineEdit and gave it the name “txtMyText”.
What’s the correct way to query the text from this QLineEdit. I assumed I could do something like
cmds.textField("txtMyText", query = True, text = True)
but that gives me an error:
# RuntimeError: Object 'txtMyText' not found.
Which, when you think about it, makes sense since a QLineEdit is not the same as a textField.
But how then do you find the QLineEdit “txtMyText” from a script?
Ack, why do I always find a solution after I post here… ?
Anyhoo, the solution I’m using now is the following:
My imports and global ui variable
from maya import OpenMayaUI as omui
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtUiTools import *
from shiboken import wrapInstance
from stringBuilder import *
import os
import maya.cmds as cmds
import pymel.core as pm
ui = "thisIsNothingForNow"
I would recommend reading the Qt Documentation when you have specific questions about a particular widget. You can often find examples in the description covering basic usage.
The docs are in C++, so it takes a little effort to translate to python.