我试图选择一个对象并显示行编辑
来自PySide import的
来自pymel import *
导入pymel.core作为pm
import maya.cmds as cmds
进口maya.mel as mel
导入maya.OpenMaya作为OpenMaya
def select_obj(obj):
list = pm.poly
print obj
button = QPushButton("select")
button.clicked.connect(select_obj)
button.show()
def desselect_obj(obj):
list = OpenMaya.MSelection()
print obj
button2 = QPushButton("disconnect")
button2.clicked.connect(select_obj)
button2.show()
edit = QLineEdit(nome)
QLineEdit.show(select_obj)
label.show()
app.exec_()
# Error: line 1: TypeError: file <maya console> line 25: 'PySide.QtGui.QLineEdit' called with wrong argument types:
PySide.QtGui.QLineEdit(function)
Supported signatures:
PySide.QtGui.QLineEdit(PySide.QtGui.QWidget = No`enter code here`ne)
PySide.QtGui.QLineEdit(unicode, PySide.QtGui.QWidget = None) #
# TypeError: select_obj() takes exactly 1 argument (0 given)
答案 0 :(得分:1)
您的代码存在很多问题。您不需要导入那么多模块(尤其是未使用的模块)。通常在使用PySide创建ui时,您将环绕一个继承自QWidget
或QMainWindow
的类。看看下面的代码,它是一个带有按钮和lineEdit的窗口的简单示例。当您按下按钮时,它会将所选对象的名称添加到lineEdit。
from PySide import QtGui, QtCore
import maya.cmds as cmds
class Window(QtGui.QWidget):
def __init__(self, parent = None):
super(Window, self).__init__(parent) # Inherit from QWidget
# Create button
self.button = QtGui.QPushButton("select")
self.button.clicked.connect(self.select_obj)
# Create line edit
self.edit = QtGui.QLineEdit()
# Create widget's layout
mainLayout = QtGui.QVBoxLayout()
mainLayout.addWidget(self.button)
mainLayout.addWidget(self.edit)
self.setLayout(mainLayout)
# Resize widget, and show it
self.resize(200, 200)
self.show()
# Function to add selected object to QLineEdit
def select_obj(self):
sel = cmds.ls(sl = True) # Get selection
if sel:
self.edit.setText(sel[0]) # Set object's name to the lineEdit
win = Window() # Create instance of the class