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] Forwarding mouse wheel events
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Forwarding mouse wheel events

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.6k 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 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?

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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      skozbial
      wrote on last edited by
      #2

      QTextEdit is subclass of QAbstractScrollArea, so you can replace the default scroll bar by your external one by calling QTextEdit::setVerticalScrollBar

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

        For some reason I missed the notification on this comment. Thanks - I will try this.

        "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
          #4

          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).

          "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
            #5

            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.

            "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