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. [SOLVED] Ignoring mouse wheel events in QTextEdit

[SOLVED] Ignoring mouse wheel events in QTextEdit

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 5.1k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    frankiefrank
    wrote on last edited by
    #1

    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?

    "Roads? Where we're going, we don't need roads."

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gvanvoor
      wrote on last edited by
      #2

      If you subclass the QTextEdit, you can override wheelEvent to ignore the event:

      @QTextEditSubClass::wheelEvent( QWheelEvent * inEvent )
      {
      inEvent->ignore();
      }
      @

      1 Reply Last reply
      0
      • F Offline
        F Offline
        frankiefrank
        wrote on last edited by
        #3

        Thanks gvanvoor, yes - I assume that's the next logical step. But why should the event filter not be enough here?

        "Roads? Where we're going, we don't need roads."

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gvanvoor
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            frankiefrank
            wrote on last edited by
            #5

            Thanks gvanvoor, your suggestion with the subclass works for me.

            "Roads? Where we're going, we don't need roads."

            1 Reply Last reply
            0
            • F Offline
              F Offline
              frankiefrank
              wrote on last edited by
              #6

              Can I attract your attention to my "sequel" issue?

              http://qt-project.org/forums/viewthread/48612/

              "Roads? Where we're going, we don't need roads."

              1 Reply Last reply
              0

              • Login

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