[SOLVED] Ignoring mouse wheel events in QTextEdit
-
I'm working with a QTextEdit as a part of another . I have my own external scrollbar on the side and I want the QTextEdit to ignore all mouse wheel events.
I tried using an event filter:
@
textEdit->installEventFilter(this);// ...
bool MyWidget::eventFilter(QObject *obj, QEvent *ev)
{
//! Ignore ALL wheel events
if (ev->type() == QEvent::Wheel)
{
return true;
}
return QObject::eventFilter(obj, ev);
}
@This doesn't seem to work - using the mouse wheel still has the effect of "moving" the text: even though I don't have enough text to "scroll" full lines, it still scrolls just a little back and forth.
Shouldn't the code I wrote be enough to ignore all mouse wheel events?
-
If you subclass the QTextEdit, you can override wheelEvent to ignore the event:
@QTextEditSubClass::wheelEvent( QWheelEvent * inEvent )
{
inEvent->ignore();
}
@ -
Thanks gvanvoor, yes - I assume that's the next logical step. But why should the event filter not be enough here?
-
There are different possibilities and I don't have enough experience with QTextEdit to say which is more likely.
I know that on some widgets like QTableView, you need to install the eventFilter on the widget's viewport instead of the widget itself (though I don't think this would be the case for wheelEvents)
Another possibility is that there's another eventFilter installed which returns true, preventing your eventFilter form being called. Say you have the following situation:
text->installEventFilter( a );
text->installEventFilter( b );
if a::eventFilter gets called first (I think this will be the case but I'm not sure) and returns true, then b::eventFilter will never be called. -
Thanks gvanvoor, your suggestion with the subclass works for me.
-
Can I attract your attention to my "sequel" issue?