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. mouseWheel event for QHeaderView of a QTableWidget

mouseWheel event for QHeaderView of a QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.4k Views
  • 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 Offline
    A Offline
    Adam Crowe
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      Adam Crowe
      wrote on last edited by
      #2

      Bump??

      Anyone have an idea about this?

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Please provide a minimal, compilable example.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Adam Crowe
          wrote on last edited by
          #4

          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
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            A 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              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?

              A Offline
              A Offline
              Adam Crowe
              wrote on last edited by
              #6

              @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
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                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