简体   繁体   English

使用PyQt进行曲线控制

[英]Curve Control With PyQt

Is there any curve control in pyqt?, I have attached a image which is based on maya gradientControl. pyqt中是否有任何曲线控件?我已附加了基于maya gradientControl的图像。 I am looking some thing similar with pyqt where I want to edit the curve and each edit should trigger some signal.Right now I can use sip and I can wrap maya gradientControl in to my pyqt window but its really not working as expected. 我正在寻找与pyqt类似的东西,我想编辑曲线,每次编辑都应该触发一些信号。 Here is the code what I am trying. 这是我正在尝试的代码。 Its just a QWidget so its very hard to find what happening when I am adding a point on curve . 它只是一个QWidget,因此很难在添加曲线点时发现发生的情况。

import os
import maya.cmds as cmds
import maya.mel as mel
import maya.OpenMayaUI as mui
import sys
import sip
from PyQt4 import QtGui, QtCore, uic
baseUI = os.path.join(os.path.dirname(__file__), "range_ctrl.ui")
baseUIClass, baseUIWidget = uic.loadUiType(baseUI)

def getMayaWindow():
    windowPointer = mui.MQtUtil.mainWindow()
    return sip.wrapinstance(long(windowPointer), QtCore.QObject)

def convertToQT(controlName):
    controlPoniter = mui.MQtUtil.findControl(controlName)
    if controlPoniter is not None:
        return sip.wrapinstance(long(controlPoniter), QtCore.QObject)

class MayaRangeCtrl(baseUIWidget, baseUIClass):
    def __init__(self, parent=getMayaWindow()):
        super(baseUIWidget, self).__init__(parent)
        self.setupUi(self)
        self.setObjectName("mayaRangeCtrl")
        self.setWindowTitle("Range Control")
        self.p1_vbox = QtGui.QVBoxLayout(self.frame)
        self.range_ctr = cmds.gradientControlNoAttr( 'mayaaaa', h=90)
        mayaQTObj = convertToQT(self.range_ctr)
        self.p1_vbox.addWidget(mayaQTObj)
        self.setCentralWidget(self.frame)
        self.show()

def main():
    myWindow = MayaRangeCtrl()

def run():
    main()

And here is the screen capture. 这是屏幕截图。

在此处输入图片说明

And the ui contain a mian window and a QFrame with. 并且ui包含一个主窗口和一个QFrame。 Here is the maya documentation 这是Maya 文档

But I am looking some pure QT widgets or some idea how we can implement this. 但是我正在寻找一些纯QT小部件或一些想法,我们应该如何实现它。 I tried with QPolygon but no idea how we can manipulate control point run time. 我尝试使用QPolygon,但不知道如何控制控制点运行时间。 any idea ? 任何想法 ?

Thanks in advance. 提前致谢。

Because the gradient control is written in the C++ side of the maya code, there is no public interface to it as a PyQt4 widget as you might have already discovered (and as far as I know). 因为渐变控件是用maya代码的C ++编写的,所以您可能已经发现(据我所知),没有作为PyQt4小部件的公共控件。

What sip will give you is a QWidget reference that lets you reparent and place it within your app as you desire. 饮将为您提供QWidget参考,您可以根据自己的意愿重新放置并放置在应用程序中。 But as for working with it from there on, your best bet is to just connect up to the python commands callbacks for the gradient control 但是从那里开始使用它,最好的选择是只连接到渐变控制python命令回调

cmds.gradientControlNoAttr(self.range_ctr, e=True, changeCommand=self.myCallback)

If the available callbacks for the gradientControlNoAttr are not enough for you, then I am afraid you will have to roll your own custom widget using your own paint events (or using the QGraphics classes). 如果gradientControlNoAttr的可用回调对您来说还不够,那么恐怕您将不得不使用自己的绘画事件(或使用QGraphics类)来滚动自己的自定义窗口小部件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM