0

I am trying to implement my own version of the QDoubleSpinBox to have it act like in Maya with int/FloatFields so you can Ctrl+click+drag to change the value.

I have this system working on a QLabel by setting the text from my value but then when I try to do it on a QDoubleSpinBox I have a problem with the mousePressEvent. It only works on the arrowButtons, not it the field itself...

here is my initial code :

class MayaLikeDoubleField(QtGui.QDoubleSpinBox):
    def __init__(self, parent):
        super(MayaLikeDoubleField, self).__init__()

        self.offset = 0

    def mousePressEvent(self, event):
        self.offset = event.x()

    def mouseMoveEvent(self, event):
        modifiers = QtGui.QApplication.keyboardModifiers()
        if modifiers == QtCore.Qt.ControlModifier:
            QtGui.QWidget.mouseMoveEvent(self, event)
            relPos = event.x()-self.offset
            print relPos*0.01
            # instead of printing I would set the value.

In this case, it doesn' work. So I have tried this :

class Widget(QtGui.QWidget):
    def __init__(self):
        super(Widget, self).__init__()
        self.layout = QtGui.QHBoxLayout(self)

        self.sbox = QtGui.QDoubleSpinBox()
        self.layout.addWidget(self.line)
        self.sbox.installEventFilter(self)

    def mousePressEvent(self, event):
        print "Main Widget Mouse Press"
        super(Widget, self).mousePressEvent(event)

    def eventFilter(self, obj, event):
        modifiers = QtGui.QApplication.keyboardModifiers()
        if modifiers == QtCore.Qt.ControlModifier:
            if self.layout.indexOf(obj) != -1:
                if event.type() == event.MouseButtonPress:
                    print "Widget click"
                if event.type() == event.MouseMove:
                    print "Widget Move"
         return super(Widget, self).eventFilter(obj, event)

And surprise ! it doesn't work ... but if i replace the QDoubleSpinBox by a QLineEdit it does work ... why ? for me it works the same way as by default the mousePressButton doesn't work on it...

Is there anything special that I am missing ?

Thanks !

Goffer
  • 97
  • 1
  • 8
  • The event does fire on the field but it only seems to happen when you click the border of it. Seems like it would be easy but I'm stumped on it too. – Green Cell Sep 25 '15 at 02:24
  • It works on the border and the side buttons if it's a SpinBox – Goffer Sep 25 '15 at 16:18

0 Answers0