Creating an Undo chunk using PyQt and Maya


#1

Hi Everyone!

I’m trying to build a script which opens the Undo Chunk when I click on a QSlider and closes it when I release it. I know how to connect sliders to functions, but I’m getting confused with events. I figured it could be done in some way using mouse press event and mouse release event. In a QSlider I use Value.connect(functionName). How can I make it work with mouse press and mouse release?

Thanks!


#2

Subclass the QSlider widget and override the functions of the mousePress and mouseRelease events.

something like this:

from PySide import QtGui as qt

class CustomSlider(qt.QSlider):
    
    def __init__(self, parent=None):
        super(CustomSlider, self).__init__(parent)
        
    def mousePressEvent(self, event):
        qt.QSlider.mousePressEvent(self, event)
        
        print 'press'
        #open undo chunk
        
    def mouseReleaseEvent(self, event):
        qt.QSlider.mouseReleaseEvent(self, event)
        
        print 'release'
        #close undo chunk
        
        
exampleSliderWidget = CustomSlider()