Search code examples
pythonpyqtqwidgetmaya

Curve Control With PyQt


Is there any curve control in pyqt?, I have attached a image which is based on 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. 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 .

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.

enter image description here

And the ui contain a mian window and a QFrame with. Here is the maya documentation

But I am looking some pure QT widgets or some idea how we can implement this. I tried with QPolygon but no idea how we can manipulate control point run time. any idea ?

Thanks in advance.


Solution

  • 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).

    What sip will give you is a QWidget reference that lets you reparent and place it within your app as you desire. 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

    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).