Thanks Anna,

in the below example there is only one widget and all my tests have shown that it is the QScrollBar that sends the wheel event, yet it won't respond to the custom method.
I have worked around this now by overwriting event() instead like this:
    def event(self, event):
        if event.type() == QEvent.Wheel:
            do stuff
        else:
            super(PageScroller, self).event(event)
            return False


Seems brute force but it works.

Cheers,
frank

On 24/12/15 7:29 am, Anna Stenwick wrote:
In the documentation for QWheelEvent it says:
Wheel events are sent to the widget under the mouse cursor, but if that widget does not handle the event they are sent to the focus widget.

Perhaps the wrong widget is being sent the event, is your scroll bar the focused widget?

Also, be sure to set this in order to receive events for your scroll bar widget:

TheQWidget.setEnabled() <http://srinikom.github.io/pyside-docs/PySide/QtGui/QWidget.html#PySide.QtGui.PySide.QtGui.QWidget.setEnabled>function can be used to enable or disable mouse and keyboard events for a widget.

I made a custom Dialog class awhile ago and handling the events was the most frustrating part, sometimes it doesn't work the way you expect it to. Try overriding QWidget.showEvent and see if your event shows up there.

On 12/22/2015 08:25 PM, Frank Rueter | OHUfx wrote:
Hi everybody,
quick Christmas question:

I am trying to re-implement a QScrollBar's wheelEvent to change it's
delta but I just can't get it right for some reason. It kinda feels like
a bug to me but am not sure (using PySide 1.0.9).

Below is a stripped down version of what I'm trying to do.
PageScroller().wheelEvent() never seems to be fired (though the wheel
does scroll the bar).
Does anybody have an idea what I'm doing wrong?

Cheers,
frank

class PageScroller(QScrollBar):
     '''Scroll widget for tool page'''

     def __init__(self, parent=None):
         super(PageScroller, self).__init__(parent)

     def wheelEvent(self, event):
         print 'received wheel event'


if __name__ == '__main__':
     def testSlot(i):
         print 'Current index changed:', i

     app = QApplication(sys.argv)
     mainWindow = QWidget()
     layout = QVBoxLayout(mainWindow)
     s = PageScroller(mainWindow)
     layout.addWidget(s)
     mainWindow.show()

     sys.exit(app.exec_())



--
ohufxLogo 50x50 <http://www.ohufx.com>     *vfx compositing
<http://ohufx.com/index.php/vfx-compositing> | *workflow customisation
and consulting <http://ohufx.com/index.php/vfx-customising>* *



_______________________________________________
PySide mailing list
PySide@qt-project.org
http://lists.qt-project.org/mailman/listinfo/pyside




--
ohufxLogo 50x50 <http://www.ohufx.com> *vfx compositing <http://ohufx.com/index.php/vfx-compositing> | *workflow customisation and consulting <http://ohufx.com/index.php/vfx-customising>* *

_______________________________________________
PySide mailing list
PySide@qt-project.org
http://lists.qt-project.org/mailman/listinfo/pyside

Reply via email to