[SOLVED] Forwarding mouse wheel events
I have a QTextEdit subclass and an external QScrollBar.
I always display a fixed number of lines, and I'd like to be able to control my scrollbar by scrolling the mouse wheel. This naturally works when the mouse cursor is on top of the scroll bar, but I want it to happen when the mouse is over the QTextEdit as well.
Subclassing the QTextEdit allows me to catch the QWheelEvent - but I'm not sure how to properly forward it.
Should I use QCoreApplication::sendEvent() or QCoreApplication::postEvent(), with the receiver being a stored reference to the scrollbar?
QTextEdit is subclass of QAbstractScrollArea, so you can replace the default scroll bar by your external one by calling QTextEdit::setVerticalScrollBar
For some reason I missed the notification on this comment. Thanks - I will try this.
This (or this alone) doesn't do the trick for me. Setting the external scrollbar to mine causes the QTextEdit to interact with it by modifying its values. I really want to have full control over my scrollbar and only get the mouse wheel functionality.
Explanation: I display only a small part of a larger data set in the QTextEdit. Once I call QTextEdit::setVerticlaScrollbar() and set the text, the scrollbar range changes based on the text I inserted (which messes up my code that calculates the scrolling range from the actual full data).
Eventually solved it like this:
I subclassed QTextEdit, and emitted my own signal for the wheel events
void TextEdit::wheelEvent(QWheelEvent *e)
QPoint numDegrees = e->angleDelta() / 8;
In the parent widget this signal is connected to a slot where I translate the delta to steps added/subtracted from the scrollbar.