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. Send QWheelEvent to Child Scrollbar
Forum Updated to NodeBB v4.3 + New Features

Send QWheelEvent to Child Scrollbar

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.0k 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.
  • E Offline
    E Offline
    exiled
    wrote on last edited by
    #1

    I am trying to pass an event from a parent to a child, but when the scrollbar doesn't handle the event (ie when you try to scroll to the max when already at the max, value does not change and event is not handled) and return it instead sends the event to it's parent. So an infinite loop is created of the parent and child trying to get each other to answer a QWheelEvent.

    @class CustomWidget : QWidget
    {
    CustomWidget() : sb(Qt::Orientation::Vertical, this) { }

    QScrollBar sb;
    
    void wheelEvent(QWheelEvent* ev) override
    { QApplication::sendEvent(&sb, ev); }
    

    };@

    1 Reply Last reply
    0
    • E Offline
      E Offline
      exiled
      wrote on last edited by
      #2

      Nobody ? All I want is for the scrollbar to move the same amount when scrolling over the custom widget as if it were over the scrollbar. Using QScrollBar::setValue() won't guarantee it'll move the same amount unless there's a QStyle variable that specifies how far the scrollbar for QWheellEvent::delta ?

      1 Reply Last reply
      0
      • T3STYT Offline
        T3STYT Offline
        T3STY
        wrote on last edited by
        #3

        I haven't worked that much with events, but what I could understand is that you're not sending a wheel event just to the child scrollbar; you're actually creating another global wheel event - which causes the loop because for each wheel event another wheel event is created.

        The solution is either to send the wheel event directly to the widget you meant (I have no idea how to do that), or to reimplement the "QScrollbar::event()":http://qt-project.org/doc/qt-5.1/qtwidgets/qscrollbar.html#event event handler function to react to the event. If the main QScrollbar widget is capturing the event so the child QScrollbar is not answering the same event, I think you may manually call the "QScrollbar::event()":http://qt-project.org/doc/qt-5.1/qtwidgets/qscrollbar.html#event function with a QEvent::Wheel parameter (a wheel event).

        Sorry for not being of any more help, I'm still a beginner in Qt and I found these solutions just by reading the docs.

        1 Reply Last reply
        0
        • E Offline
          E Offline
          exiled
          wrote on last edited by
          #4

          That worked perfectly (calling sb.event(ev) in wheelEvent), I should have read more into what QApplication::sendEvent did.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            exiled
            wrote on last edited by
            #5

            e: error posting...

            1 Reply Last reply
            0
            • T3STYT Offline
              T3STYT Offline
              T3STY
              wrote on last edited by
              #6

              I'm glad it helped ;)

              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