1

I am trying to get QGesture events in my widget (subclass of QWidget). I have the following in my constructor:

setAttribute(Qt::WA_AcceptTouchEvents);
setAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
grabGesture(Qt::SwipeGesture);
grabGesture(Qt::PanGesture);
grabGesture(Qt::PinchGesture);

And I have my own event function:

bool MyWidget::event(QEvent *event)
{
  if(event->type() == QEvent::Gesture)
  {
    TRACE("Gesture");
  }
  if(event->type() == QEvent::GestureOverride)
  {
    TRACE("Gesture override");
  }
  if(event->type() == QEvent::Enter)
  {
    TRACE("Mouse enter");
  }
  return true;
}

On windows 7 I receive mouse enter events but nothing else. (I am using the ms surface sdk input simulator to generate touch events as suggested here). Very occasionally I get the message

QGestureManager::deliverEvent: could not find the target for gesture.

but cannot easily reproduce this.

Why am I not receiving gesture events?

user3270082
  • 21
  • 1
  • 5
  • Is it possible that the MS Surface SDK input simulator doesn't generate touch events that are compatible with the Qt event system? From what you've described it really seems like the case. I have a Raspberry Pi with the 7" official multi-touch screen and Qt's touch functionality works without any issues whatsoever. – rbaleksandar Dec 05 '16 at 10:05

2 Answers2

2

You must not set the Qt::WA_TouchPadAcceptSingleTouchEvents on a widget. The documentation for enum Qt::WidgetAttribute lists the respective attribute in a section preceded by

Warning: This flag must never be set or cleared by the widget's author.

This used to be more explicit in earlier documentation (e.g. enum Qt::WidgetAttribute for Qt 4.8).

IInspectable
  • 46,945
  • 8
  • 85
  • 181
1

You need to have a parent mainwindow to be able to grab the gestures, see QTBUG #14224.

ismail
  • 46,010
  • 9
  • 86
  • 95
  • I tried making sure my widget has a QMainWindow parent but this doesn't help. I also tried the imagegestures qt example and no gestures are recognised using the ms surface sdk input simulator. I also tried the imagegestures example on ios 5 on an ipad 1 and no gestures are recognised there either. – user3270082 Feb 07 '14 at 13:41