Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Determining the source of a QMouseEvent
QtWS25 Last Chance

Determining the source of a QMouseEvent

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 2 Posters 5.1k 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
    mbarclaygmail.com
    wrote on last edited by
    #1

    My QML/C++ GUI receives touch screen and mouse inputs. All events come through as QMouseEvents, but I need to handle them differently depending if the source device is the touch screen or if it is the mouse (or touchpad mouse). Is there a way to look up the source device of a QMouseEvent?

    Thanks,
    Matt

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      Why do you want to distinguish between the two? As far as the OS is concerned, both devices are pointer devices and therefore they probably get the same treatment.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbarclaygmail.com
        wrote on last edited by
        #3

        Basically, there are two ways of interacting with my GUI: Either a traditional touch screen, or by using a mouse (which is actually a track ball mouse) as a remote control from a couple feet away. It's difficult to use flicking and navigate efficiently with the mouse, so I have some special QML MouseArea's that simplify scrolling with the mouse just by entering the area and moving the mouse up or down. I use some C++ tricks ala QCursor::setPos() to scroll the entire length of a QML ListView without having to drag the mouse to the bottom of the screen, then grab, and scroll to the top.

        The problem is that the touch screen QMouseEvent's get handled by my mouse-only QML MouseArea's. If I could tell the difference between a touch screen mouse event and a normal mouse event, then I could ignore touches inside those mouse-only QML MouseArea's.

        Also, I hide the cursor when touch screen events come in, and show it when mouse events happen.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          I'm not aware of any way of differentiating between one or the other input device. I guess, though, that mouse gestures may be interesting for your case. It will give you a slightly different user experience, but none of that differentiating stuff. It's just a thought.

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mbarclaygmail.com
            wrote on last edited by
            #5

            I've been experimenting with reading raw linux input events from my mouse. I can interpret the event and post a QMouseEvent to my QDeclarativeView::viewport() widget. Those events make it to my QML. It would be awesome if I could set a keyboard modifier on my QMouseEvent so the QML could distinguish the mouse event from a touch event.

            In my Mouse Reader:
            @
            QMouseEvent m(QEvent::MouseMove, QCursor::pos(), view->mapToGlobal(QCursor::pos()),
            Qt::NoButton, Qt::NoButton, Qt::MetaModifier);

            // Why does Qt discard this event?
            QApplication::sendEvent(view->viewport(), &m);
            @

            In my QML:
            @
            MouseArea {
            anchors.fill: parent
            hoverEnabled: true

                onPositionChanged: {
                    if(mouse.modifiers & Qt.MetaModifier) {
                        // mouse.modifiers is NEVER set
                        console.log("++ Mouse Move!" + " " + mouse.button + " " + mouse.modifiers + " " + mouse.buttons)
                    } else {
                        console.log("++ Touch Move! " + " " + mouse.button + " " + mouse.modifiers + " " + mouse.buttons)
                    }
                }
            

            }
            @

            But I never get Mouse Moves, only Touch Moves. Qt seems to discard a QMouseEvent(QEvent::MouseMove) with the keyboard modifier.

            This scheme works for my mouse press/release. I can distinguish those using mouse.modifiers.

            Does anyone know why Qt discards MouseMove's when the keyboard modifier is set?

            Thanks,
            Matt

            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