May 16, 2011

MattB MattB
Lab Rat
35 posts

Determining the source of a QMouseEvent

 

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

4 replies

May 16, 2011

Franzk Franzk
Lab Rat
834 posts

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.

 Signature 

“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

May 16, 2011

MattB MattB
Lab Rat
35 posts

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.

May 16, 2011

Franzk Franzk
Lab Rat
834 posts

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.

 Signature 

“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

May 21, 2011

MattB MattB
Lab Rat
35 posts

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:

  1. QMouseEvent m(QEvent::MouseMove, QCursor::pos(), view->mapToGlobal(QCursor::pos()),
  2.                   Qt::NoButton, Qt::NoButton, Qt::MetaModifier);
  3.  
  4. // Why does Qt discard this event?
  5. QApplication::sendEvent(view->viewport(), &m);

In my QML:

  1. MouseArea {
  2.         anchors.fill: parent
  3.         hoverEnabled: true
  4.  
  5.         onPositionChanged: {
  6.             if(mouse.modifiers & Qt.MetaModifier) {
  7.                 // mouse.modifiers is NEVER set
  8.                 console.log("++ Mouse Move!" + " " + mouse.button + " " + mouse.modifiers + " " + mouse.buttons)
  9.             } else {
  10.                 console.log("++ Touch Move! " + " " + mouse.button + " " + mouse.modifiers + " " + mouse.buttons)
  11.             }
  12.         }
  13. }

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

 
  ‹‹ QML Camera doesn’t show full-screen      Qt and VxWorks ››

You must log in to post a reply. Not a member yet? Register here!