Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved mouseWheel event for QHeaderView of a QTableWidget

    General and Desktop
    2
    7
    412
    Loading More Posts
    • 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.
    • A
      Adam Crowe last edited by

      Hello,

      I have a few custom QTableWidgets in a QHBoxLaout housed in a scrollable view. In the custom QTableWidget, I override the mouseWheel event to filter out the vertical mouse scroll events so they get passed on up to the scrollable view and the UI scrolls between the QTableWidgets rather than attempt to scroll the content of each QTableWidget.

      This all works wonderfully unless the scroll event happens over the horizontal header. This doesn't generate any mouseWheel event, and it also doesn't generate ANY events in eventFilter! So the scroll basically has no effect whatsoever and nothing scrolls one way or another.

      I tried creating a custom QHeaderView with an even filter and setting the horizontal header to it but it also doesn't receive any scroll events whatsoever.

      Does anyone know how to capture (and ignore) the scroll events of a horizontal header of a QTableWidget?

      Thank you! Adam

      1 Reply Last reply Reply Quote 0
      • A
        Adam Crowe last edited by

        Bump??

        Anyone have an idea about this?

        1 Reply Last reply Reply Quote 0
        • Christian Ehrlicher
          Christian Ehrlicher Lifetime Qt Champion last edited by

          Please provide a minimal, compilable example.

          Qt has to stay free or it will die.

          1 Reply Last reply Reply Quote 0
          • A
            Adam Crowe last edited by

            I have a custom QTableWidget class with an overloaded wheelEvent:

            void MyTableWidget::wheelEvent(QWheelEvent *event)
            {
                // Pass vertical scrolls to the parent to scroll the list of editors
                // but pass the horizontal scroll to the horizontal scrollbar to scroll this QTableWidget.
                if (event->angleDelta().x() != 0)
                {
                    QApplication::sendEvent(this->horizontalScrollBar(), event);
            
                    if (event->angleDelta().y() != 0)
                    {
                        event->ignore();
                    }
                }
                else
                {
                    event->ignore();
                }
            }
            

            The above code works perfectly except that wheelEvent doesn't get triggered when the mouse is over the header area of a QTableWidget. I haven't managed to track what does get triggered when the scroll even occurs over the header. I would like to pass that scroll event to the parent of the QTableWidget just like in the code above.

            Thank you! Adam

            1 Reply Last reply Reply Quote 0
            • Christian Ehrlicher
              Christian Ehrlicher Lifetime Qt Champion last edited by

              This is no minimal, compilable example but when you want to retrieve the wheelEvent of the header shouldn't you install an event filter on the header then?

              Qt has to stay free or it will die.

              A 1 Reply Last reply Reply Quote 0
              • A
                Adam Crowe @Christian Ehrlicher last edited by

                @Christian-Ehrlicher Thank you Christian,

                I realise it's not a full compilable code and I apologise - it would be a mission to extract the relevant code from this massive app.

                I have tried installing a filter in the MyTableWidget's constructor on the horizontalHeader (QHeaderView) object. The eventFilter does receive the QEvent::Wheel event but I haven't managed to pass it on to either the MyTableWidget itself (presumably to be then caught by the wheelEvent above which does work already) or just return false or do an event->ignore() on it.

                I also tried to do a QApplication::sendEvent(this, wheelEvent) to force forwarding this event to the MyTableWidget but it also doesn't do anything.

                The result is always that nothing scrolls up or down.

                1 Reply Last reply Reply Quote 0
                • Christian Ehrlicher
                  Christian Ehrlicher Lifetime Qt Champion last edited by

                  @Adam-Crowe said in mouseWheel event for QHeaderView of a QTableWidget:

                  The eventFilter does receive the QEvent::Wheel event but I haven't managed to pass it on to either the MyTableWidget itself (presumably to be then caught by the wheelEvent above which does work already) or just return false or do an event->ignore() on it.

                  Please show some code... minimal, fully compilable.

                  Qt has to stay free or it will die.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post