[SOLVED] Forwarding mouse wheel events
-
wrote on 17 Oct 2014, 15:36 last edited by
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?
-
wrote on 19 Oct 2014, 20:43 last edited by
QTextEdit is subclass of QAbstractScrollArea, so you can replace the default scroll bar by your external one by calling QTextEdit::setVerticalScrollBar
-
wrote on 23 Oct 2014, 13:40 last edited by
For some reason I missed the notification on this comment. Thanks - I will try this.
-
wrote on 23 Oct 2014, 13:55 last edited by
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).
-
wrote on 23 Oct 2014, 15:28 last edited by
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;if (!numDegrees.isNull())
emit wheelDelta(numDegrees);e->ignore();
}
@In the parent widget this signal is connected to a slot where I translate the delta to steps added/subtracted from the scrollbar.
1/5