Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How set mouse scrolling as a shortcut
Qt 6.12 LTS is out! See what's new in the release blog

How set mouse scrolling as a shortcut

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.0k 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.
  • M Offline
    M Offline
    Mary02
    wrote on last edited by
    #1

    I have a Qt application and I want to set mouse wheel as a shortcut.

    Now when I turn off possibility of use shortcuts I can't use keys but still the mouse wheel works. How can I block mouse wheel when I turn off possibility of use shortcuts?

    jsulmJ 1 Reply Last reply
    0
    • M Mary02

      I have a Qt application and I want to set mouse wheel as a shortcut.

      Now when I turn off possibility of use shortcuts I can't use keys but still the mouse wheel works. How can I block mouse wheel when I turn off possibility of use shortcuts?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mary02 You can implement an event filter, see https://doc.qt.io/qt-5/eventsandfilters.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mary02
        wrote on last edited by
        #3

        Thanks, but I have a problem with it. I add eventFilter in file where is my object:

        bool obj::eventFilter(QObject *object, QEvent *event)
        {
            if (event->type() == QEvent::Wheel) {
                return true;
            }
        
            return QObject::eventFilter(object, event);
        }
        

        and now mouse wheel is totally blocked. Bool variable which says if shortcuts are on/off is in different file and it's private. How can I add this variable to my eventFilter?

        jsulmJ 1 Reply Last reply
        0
        • M Mary02

          Thanks, but I have a problem with it. I add eventFilter in file where is my object:

          bool obj::eventFilter(QObject *object, QEvent *event)
          {
              if (event->type() == QEvent::Wheel) {
                  return true;
              }
          
              return QObject::eventFilter(object, event);
          }
          

          and now mouse wheel is totally blocked. Bool variable which says if shortcuts are on/off is in different file and it's private. How can I add this variable to my eventFilter?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mary02 said in How set mouse scrolling as a shortcut:

          How can I add this variable to my eventFilter?

          The Qt way is to use signals/slots to communicate the change of the shortcut changes to whatever part of your app needs to know.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2

          • Login

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