Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDoubleSpinBox + mousePressEvent
QtWS25 Last Chance

QDoubleSpinBox + mousePressEvent

Scheduled Pinned Locked Moved General and Desktop
eventclickevent
9 Posts 2 Posters 4.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Goffer
    wrote on 23 Sept 2015, 19:10 last edited by Goffer
    #1

    Hi Qt comunity !

    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 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 !

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Goffer
      wrote on 23 Sept 2015, 19:36 last edited by
      #2

      For the time being, I will re create the QspinBox with a QLineEdit so I will get working. But I don't give up on finding why it doesn't work.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 23 Sept 2015, 19:55 last edited by
        #3

        Hi,

        You should try to put your filter on the QLineEdit from the QDoubleSpinBox. You can get it using QDoubleSpinBox::lineEdit method

        Hope it helps

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        G 1 Reply Last reply 23 Sept 2015, 21:22
        0
        • S SGaist
          23 Sept 2015, 19:55

          Hi,

          You should try to put your filter on the QLineEdit from the QDoubleSpinBox. You can get it using QDoubleSpinBox::lineEdit method

          Hope it helps

          G Offline
          G Offline
          Goffer
          wrote on 23 Sept 2015, 21:22 last edited by
          #4

          @SGaist
          It doesn't work, here is the raised error :
          'builtin_function_or_method' object has no attribute 'installEventFilter'

          but was a nice try.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 23 Sept 2015, 21:44 last edited by
            #5

            Didn't you forgot the parenthesis ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            G 1 Reply Last reply 23 Sept 2015, 21:52
            0
            • S SGaist
              23 Sept 2015, 21:44

              Didn't you forgot the parenthesis ?

              G Offline
              G Offline
              Goffer
              wrote on 23 Sept 2015, 21:52 last edited by Goffer
              #6

              @SGaist
              nope i didn't but I forgot to save changes ^^ but stil, it doesn't work. no error raised this time and still not displaying the click print.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Goffer
                wrote on 23 Sept 2015, 22:03 last edited by Goffer
                #7

                from my second example, I need to access the focusOutEvent of my QLineEdit, how can I reach that ? I don't want to subclass QLineEdit ...

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 23 Sept 2015, 22:12 last edited by
                  #8

                  Again, the filter is your friend, QFocusEvent gives you that information.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  G 1 Reply Last reply 23 Sept 2015, 22:17
                  0
                  • S SGaist
                    23 Sept 2015, 22:12

                    Again, the filter is your friend, QFocusEvent gives you that information.

                    G Offline
                    G Offline
                    Goffer
                    wrote on 23 Sept 2015, 22:17 last edited by Goffer
                    #9

                    @SGaist
                    I have tried to add a focusOut event in my loop but it doesn't detect it ...

                    if event.type() == event.FocusOut:
                        print "Widget focusOut"
                    
                    1 Reply Last reply
                    0

                    2/9

                    23 Sept 2015, 19:36

                    7 unread
                    • Login

                    • Login or register to search.
                    2 out of 9
                    • First post
                      2/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved