0

我正在尝试选择一个对象并显示行编辑

from PySide import * from pymel import *
import pymel.core as pm import maya.cmds as cmds import maya.mel as mel import maya.OpenMaya as 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)
4

1 回答 1

1

你的代码有很多问题。您不需要导入那么多模块(尤其是未使用的模块)。通常,在使用 PySide 创建 ui 时,您会包装一个继承自 aQWidget或的类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
于 2015-09-09T06:07:41.223 回答