[Qt-interest] cannot grab gesture with qgraphicsobject

Wathek LOUED wathek at gmail.com
Mon Mar 14 13:35:51 CET 2011


Thank you so much Sean for your help I'm opening a new bug.

On Mon, Mar 14, 2011 at 1:33 PM, Sean Hayes <sean.t.hayes at vanderbilt.edu>wrote:

> Wathek,
>
> I would assume that this is a Qt bug then. I recommend creating a bug
> report at http://bugreports.qt.nokia.com. I wish I could have been more
> help.
>
> Sean
>
>
> On Mon, Mar 14, 2011 at 5:21 AM, Wathek LOUED <wathek at gmail.com> wrote:
>
>> Sean,
>>
>> Unfortunatly even using Qt 4.7.2 under GNU/Linux 64bits doesn't change
>> anything. I still cannot grab gesture in QGraphicsObject.
>>
>> Using the example you sent to me I still getting the message
>> QGestureManager::deliverEvent: could not find the target for gesture.
>>
>> Sincerely
>> W.L
>>
>>
>> On Fri, Mar 11, 2011 at 4:17 PM, Wathek LOUED <wathek at gmail.com> wrote:
>>
>>> Sean,
>>>
>>> I just tried your code and with Qt 4.6.3 and Debian 6.0 I'm
>>> getting QGestureManager::deliverEvent: could not find the target for gesture
>>> when I tap on the button but outside the button (on QGraphicsView) it works.
>>> But not with the QGraphicsObject.
>>>
>>> I'm downloading the sources of Qt 4.7.2 I'd like to try with that.
>>>
>>> Thank you
>>>
>>> On Fri, Mar 11, 2011 at 4:06 PM, Wathek LOUED <wathek at gmail.com> wrote:
>>>
>>>> Sean,
>>>>
>>>> I'm giving your code a try. I'm using Debian Squeeze with Qt 4.6.3.
>>>>
>>>>
>>>> On Fri, Mar 11, 2011 at 3:50 PM, Sean Hayes <
>>>> sean.t.hayes at vanderbilt.edu> wrote:
>>>>
>>>>> Wathek,
>>>>>
>>>>> When I try the code I am getting gesture events in the
>>>>> QGraphicsObject/PushButtonItem. The state of these gesture events are
>>>>> Qt::GestureStarted. Also, I am no longer getting the "QGestureManager::deliverEvent:
>>>>> could not find the target for gesture" error.
>>>>>
>>>>> I am using Windows 7 and Qt 4.7.2. What is your setup? Attached is my
>>>>> example program based on your code. Let me know if that example works on
>>>>> your system.
>>>>>
>>>>> Sean
>>>>>
>>>>>
>>>>> On Fri, Mar 11, 2011 at 5:11 AM, Wathek LOUED <wathek at gmail.com>wrote:
>>>>>
>>>>>> Sean,
>>>>>>
>>>>>> I'm sorry but your changes doesn't make any difference. But there's
>>>>>> one thing that I don't understand why do the QGesture::state() doesn't
>>>>>> change ? it's always the same equal to 0 which mean NoGesture.
>>>>>>
>>>>>>
>>>>>> On Thu, Mar 10, 2011 at 6:22 PM, Wathek LOUED <wathek at gmail.com>wrote:
>>>>>>
>>>>>>> Hi Sean,
>>>>>>>
>>>>>>> Thank you for your reponse I'm trying that and I'll tell you if it's
>>>>>>> Ok.
>>>>>>>
>>>>>>> Thank you so much.
>>>>>>>
>>>>>>> Sincerely
>>>>>>> Wathek
>>>>>>>
>>>>>>>
>>>>>>> On Thu, Mar 10, 2011 at 5:17 PM, Sean Hayes <
>>>>>>> sean.t.hayes at vanderbilt.edu> wrote:
>>>>>>>
>>>>>>>> The problem is that in your TabGestureRecognizer you are setting the
>>>>>>>> result to canceled for gestures that have not been triggered (e.g.,
>>>>>>>> non-touch events). Note the changes I made to your recognize() function
>>>>>>>> below. Also, note that you do not need the mouse event code there.
>>>>>>>>
>>>>>>>> QGestureRecognizer::Result TapGestureRecognizer::recognize(QGesture
>>>>>>>> *state, QObject *, QEvent *event)
>>>>>>>> {
>>>>>>>>  TapGesture *q = static_cast<TapGesture *>(state);
>>>>>>>> const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
>>>>>>>>  QGestureRecognizer::Result result = *QGestureRecognizer::Ignore*;
>>>>>>>>
>>>>>>>> switch (event->type()) {
>>>>>>>>  case QEvent::TouchBegin: {
>>>>>>>> q->setPosition(ev->touchPoints().at(0).pos());
>>>>>>>>  q->setHotSpot(ev->touchPoints().at(0).screenPos());
>>>>>>>> q->start();
>>>>>>>>  result = QGestureRecognizer::MayBeGesture;
>>>>>>>> break;
>>>>>>>>  }
>>>>>>>> case QEvent::TouchUpdate:
>>>>>>>>  case QEvent::TouchEnd: {
>>>>>>>> if (ev->touchPoints().size() == 1) {
>>>>>>>>  QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
>>>>>>>> QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
>>>>>>>>  if (delta.manhattanLength() <= Delta && q->elapsed() <=
>>>>>>>> TimerInterval && event->type() == QEvent::TouchEnd)
>>>>>>>>  result = QGestureRecognizer::TriggerGesture;
>>>>>>>> else* if(q->state() == Qt::GestureUpdated || q->state() ==
>>>>>>>> Qt::GestureStarted)*
>>>>>>>>  result = QGestureRecognizer::CancelGesture;
>>>>>>>> }
>>>>>>>>  break;
>>>>>>>> }
>>>>>>>>  }
>>>>>>>> return result;
>>>>>>>>  }
>>>>>>>>
>>>>>>>> On Wed, Mar 9, 2011 at 10:34 AM, Wathek LOUED <wathek at gmail.com>wrote:
>>>>>>>>
>>>>>>>>> Hi Till,
>>>>>>>>>
>>>>>>>>> Thank you for your response I've already seen your bug post but
>>>>>>>>> unfortunatly that doesn't help. Here are some part of my code :
>>>>>>>>>
>>>>>>>>> *gesturerecognizer class :*
>>>>>>>>> *
>>>>>>>>> *
>>>>>>>>> #ifndef GESTURERECOGNIZER_H
>>>>>>>>> #define GESTURERECOGNIZER_H
>>>>>>>>>
>>>>>>>>> #include "tapgesture.h"
>>>>>>>>> #include "tapandholdgesture.h"
>>>>>>>>>
>>>>>>>>> #include <QGestureRecognizer>
>>>>>>>>> #include <QGesture>
>>>>>>>>> #include <QEvent>
>>>>>>>>> #include <QObject>
>>>>>>>>> #include <QHash>
>>>>>>>>>
>>>>>>>>> class TapGestureRecognizer: public QGestureRecognizer
>>>>>>>>> {
>>>>>>>>> public:
>>>>>>>>> TapGestureRecognizer();
>>>>>>>>>  QGesture *create(QObject *target);
>>>>>>>>> QGestureRecognizer::Result recognize(QGesture *state, QObject
>>>>>>>>> *watched, QEvent *event);
>>>>>>>>>  void reset(QGesture *state);
>>>>>>>>> private:
>>>>>>>>> enum { TimerInterval = 400  };
>>>>>>>>> enum { Delta = 20 };
>>>>>>>>>  QHash<long, TapGesture *> touchPoints;
>>>>>>>>> };
>>>>>>>>> #endif
>>>>>>>>>
>>>>>>>>> #include "gesturerecognizer.h"
>>>>>>>>>
>>>>>>>>> #include <QWidget>
>>>>>>>>> #include <QTouchEvent>
>>>>>>>>> #include <QDebug>
>>>>>>>>> /*******************************************************
>>>>>>>>>  * TapGesture Recognizer
>>>>>>>>>  *******************************************************/
>>>>>>>>> TapGestureRecognizer::TapGestureRecognizer()
>>>>>>>>> {}
>>>>>>>>>
>>>>>>>>> QGesture *TapGestureRecognizer::create(QObject *target)
>>>>>>>>> {
>>>>>>>>> if (target && target->isWidgetType())
>>>>>>>>>  static_cast<QWidget
>>>>>>>>> *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
>>>>>>>>> return new TapGesture;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> QGestureRecognizer::Result TapGestureRecognizer::recognize(QGesture
>>>>>>>>> *state, QObject *, QEvent *event)
>>>>>>>>> {
>>>>>>>>> TapGesture *q = static_cast<TapGesture *>(state);
>>>>>>>>>  const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
>>>>>>>>> QGestureRecognizer::Result result =
>>>>>>>>> QGestureRecognizer::CancelGesture;
>>>>>>>>>
>>>>>>>>> switch (event->type()) {
>>>>>>>>> case QEvent::TouchBegin: {
>>>>>>>>> q->setPosition(ev->touchPoints().at(0).pos());
>>>>>>>>>  q->setHotSpot(ev->touchPoints().at(0).screenPos());
>>>>>>>>> q->start();
>>>>>>>>> result = QGestureRecognizer::MayBeGesture;
>>>>>>>>>  break;
>>>>>>>>> }
>>>>>>>>> case QEvent::TouchUpdate:
>>>>>>>>> case QEvent::TouchEnd: {
>>>>>>>>>  if (ev->touchPoints().size() == 1) {
>>>>>>>>> QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
>>>>>>>>> QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
>>>>>>>>>  if (delta.manhattanLength() <= Delta && q->elapsed() <=
>>>>>>>>> TimerInterval && event->type() == QEvent::TouchEnd)
>>>>>>>>> result = QGestureRecognizer::TriggerGesture;
>>>>>>>>>  else
>>>>>>>>> result = QGestureRecognizer::CancelGesture;
>>>>>>>>> }
>>>>>>>>>  break;
>>>>>>>>> }
>>>>>>>>> case QEvent::MouseButtonPress:
>>>>>>>>> case QEvent::MouseMove:
>>>>>>>>>  case QEvent::MouseButtonRelease: {
>>>>>>>>> result = QGestureRecognizer::Ignore;
>>>>>>>>> break;
>>>>>>>>>  }
>>>>>>>>> default: {
>>>>>>>>> result = QGestureRecognizer::Ignore;
>>>>>>>>>  break;
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> return result;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> void TapGestureRecognizer::reset(QGesture *state)
>>>>>>>>> {
>>>>>>>>> TapGesture *q = static_cast<TapGesture *>(state);
>>>>>>>>> q->setPosition(QPointF());
>>>>>>>>>  QGestureRecognizer::reset(state);
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> *My QGraphicsView class :*
>>>>>>>>> *
>>>>>>>>> *
>>>>>>>>> #ifndef FRMACCUEIL_H
>>>>>>>>> #define FRMACCUEIL_H
>>>>>>>>>
>>>>>>>>> #include "gesture/gesturerecognizer.h"
>>>>>>>>>
>>>>>>>>> #include <QGraphicsView>
>>>>>>>>> #include <QGraphicsScene>
>>>>>>>>> #include <QGestureEvent>
>>>>>>>>> #include <QEvent>
>>>>>>>>> #include <QTouchEvent>
>>>>>>>>> #include <QHash>
>>>>>>>>>
>>>>>>>>> class FrmAccueil: public QGraphicsView
>>>>>>>>> {
>>>>>>>>> Q_OBJECT
>>>>>>>>> public:
>>>>>>>>> FrmAccueil(QGraphicsScene *scene=0, QWidget *parent=0);
>>>>>>>>> bool viewportEvent(QEvent *event);
>>>>>>>>>
>>>>>>>>> private:
>>>>>>>>> void gestureEvent(QGestureEvent *event);
>>>>>>>>> Qt::GestureType tapGesture;
>>>>>>>>>  TapGestureRecognizer *tapGestureRecognizer;
>>>>>>>>> };
>>>>>>>>>
>>>>>>>>> #endif
>>>>>>>>>
>>>>>>>>> #include "frmaccueil.h"
>>>>>>>>>
>>>>>>>>> #include <QDebug>
>>>>>>>>> #include <QGestureRecognizer>
>>>>>>>>>
>>>>>>>>> FrmAccueil::FrmAccueil(QGraphicsScene *scene, QWidget *parent)
>>>>>>>>>    :QGraphicsView(scene, parent)
>>>>>>>>>  {
>>>>>>>>> tapGestureRecognizer = new TapGestureRecognizer();
>>>>>>>>>
>>>>>>>>> tapGesture =
>>>>>>>>> QGestureRecognizer::registerRecognizer(tapGestureRecognizer);
>>>>>>>>>
>>>>>>>>>         viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
>>>>>>>>> viewport()->grabGesture(tapGesture);
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>  bool FrmAccueil::viewportEvent(QEvent *event)
>>>>>>>>> {
>>>>>>>>> if (event->type() == QEvent::Gesture)
>>>>>>>>> gestureEvent(static_cast<QGestureEvent*>(event));
>>>>>>>>>
>>>>>>>>> return QGraphicsView::viewportEvent(event);
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> void FrmAccueil::gestureEvent(QGestureEvent *event)
>>>>>>>>> {
>>>>>>>>>  if (event->gesture(tapGesture))
>>>>>>>>> qDebug("TAP GESTURE");
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> *My QGraphicsScene class:*
>>>>>>>>>
>>>>>>>>> #ifndef PUSHBUTTONITEM_H
>>>>>>>>> #define PUSHBUTTONITEM_H
>>>>>>>>>
>>>>>>>>> #include "gesture/gesturerecognizer.h"
>>>>>>>>>
>>>>>>>>> #include <QGraphicsObject>
>>>>>>>>> #include <QEvent>
>>>>>>>>> #include <QGestureEvent>
>>>>>>>>> #include <QPixmap>
>>>>>>>>> #include <QPainter>
>>>>>>>>>
>>>>>>>>> class PushButtonItem:public QGraphicsObject
>>>>>>>>> {
>>>>>>>>> Q_OBJECT
>>>>>>>>> public:
>>>>>>>>> enum ShapeMode {
>>>>>>>>> MaskShape,
>>>>>>>>> BoundingRectShape,
>>>>>>>>>  HeuristicMaskShape
>>>>>>>>> };
>>>>>>>>>
>>>>>>>>> PushButtonItem(QGraphicsItem *parent=0);
>>>>>>>>>  QPainterPath shape() const;
>>>>>>>>>
>>>>>>>>> /* QGraphicsPixmapItem */
>>>>>>>>> QPixmap pixmap() const;
>>>>>>>>>  void setPixmap(const QPixmap &pixmap);
>>>>>>>>>
>>>>>>>>> Qt::TransformationMode transformationMode() const;
>>>>>>>>>  void setTransformationMode(Qt::TransformationMode
>>>>>>>>> transformation);
>>>>>>>>>
>>>>>>>>> QRectF boundingRect() const;
>>>>>>>>>  void paint(QPainter *painter, const QStyleOptionGraphicsItem
>>>>>>>>> *option, QWidget *widget=0);
>>>>>>>>>
>>>>>>>>> protected:
>>>>>>>>> bool sceneEvent(QEvent *event);
>>>>>>>>>
>>>>>>>>> private:
>>>>>>>>> void gestureEvent(QGestureEvent *event);
>>>>>>>>>
>>>>>>>>> ButtonType type;
>>>>>>>>>
>>>>>>>>> QList<GraphicsLineItem *> edgeList;
>>>>>>>>>  TapGestureRecognizer *tapGestureRecognizer;
>>>>>>>>> Qt::GestureType tapGesture;
>>>>>>>>>
>>>>>>>>> // QGraphicsPixmapItem
>>>>>>>>> QPixmap pix;
>>>>>>>>> bool hasShape;
>>>>>>>>>  Qt::TransformationMode transfMode;
>>>>>>>>> };
>>>>>>>>>
>>>>>>>>> #endif
>>>>>>>>>
>>>>>>>>> #include "pushbuttonitem.h"
>>>>>>>>>
>>>>>>>>> #include <QPixmap>
>>>>>>>>>
>>>>>>>>> #include <QDebug>
>>>>>>>>> #include <QTouchEvent>
>>>>>>>>> #include <QGestureRecognizer>
>>>>>>>>>
>>>>>>>>> PushButtonItem::PushButtonItem(QGraphicsItem *parent)
>>>>>>>>>        :QGraphicsObject(parent)
>>>>>>>>> {
>>>>>>>>> setFlags(QGraphicsItem::ItemIsMovable |
>>>>>>>>> QGraphicsItem::ItemSendsGeometryChanges);
>>>>>>>>>
>>>>>>>>> setTransformationMode(Qt::SmoothTransformation);
>>>>>>>>>   setAcceptTouchEvents(true);
>>>>>>>>>
>>>>>>>>> tapGestureRecognizer = new TapGestureRecognizer();
>>>>>>>>>  tapGesture =
>>>>>>>>> QGestureRecognizer::registerRecognizer(tapGestureRecognizer);
>>>>>>>>>
>>>>>>>>> grabGesture(tapGesture);
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> QPainterPath PushButtonItem::shape() const
>>>>>>>>> { return QGraphicsItem::shape();     }
>>>>>>>>>
>>>>>>>>> bool PushButtonItem::sceneEvent(QEvent *event)
>>>>>>>>> {
>>>>>>>>> qDebug("Event received");
>>>>>>>>> if (event->type() == QEvent::Gesture)
>>>>>>>>>  gestureEvent(static_cast<QGestureEvent *>(event));
>>>>>>>>> return true;
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> void PushButtonItem::gestureEvent(QGestureEvent *event)
>>>>>>>>> {
>>>>>>>>> if (event->gesture(tapGesture))
>>>>>>>>> qDebug("button Tapped");
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> /***************************************************************
>>>>>>>>>  * QGraphicsPixmapItem Reimplementation
>>>>>>>>>  ***************************************************************/
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I cannot really see where's the problem the QGraphicsView receive
>>>>>>>>> the gestureEvent but not the QGraphicsObject.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Thank you so much
>>>>>>>>>
>>>>>>>>> Sincerely
>>>>>>>>> W.L
>>>>>>>>>
>>>>>>>>> On Mon, Mar 7, 2011 at 11:02 PM, Till Oliver Knoll <
>>>>>>>>> till.oliver.knoll at gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Am 07.03.11 19:31, schrieb Wathek LOUED:
>>>>>>>>>>  > Hi,
>>>>>>>>>>  >
>>>>>>>>>>  > I got a problem with QGraphicsObject, I cannot grab gesture and
>>>>>>>>>> I'm
>>>>>>>>>>  > getting this message : QGestureManager::deliverEvent: could not
>>>>>>>>>> find the
>>>>>>>>>>  > target for gesture.
>>>>>>>>>>
>>>>>>>>>> My experience up to Qt 4.7.1 is that QGestures are not as "mature"
>>>>>>>>>> as
>>>>>>>>>> one would wish, especially on Mac.
>>>>>>>>>>
>>>>>>>>>> I had a somewhat similar issue that Pan gesture would not get
>>>>>>>>>> through to
>>>>>>>>>> QGraphicsObjects in a QGraphicsScene. It turned out that this is a
>>>>>>>>>> "design issue" (how Gestures are implemented respective how items
>>>>>>>>>> in a
>>>>>>>>>> scene deal with events) and won't be fixed:
>>>>>>>>>>
>>>>>>>>>>   http://bugreports.qt.nokia.com/browse/QTBUG-16618
>>>>>>>>>>
>>>>>>>>>> There is an example attached which shows how gestures SHOULD work
>>>>>>>>>> with
>>>>>>>>>> QGraphicsObjects. Note that up to Qt 4.6.x also the QGraphicsView
>>>>>>>>>> (the
>>>>>>>>>> view widget thereof!) had to grab the same gestures as the item
>>>>>>>>>> itself.
>>>>>>>>>> This should not be necessary anymore with Qt 4.7.x.
>>>>>>>>>>
>>>>>>>>>> So in my case the QGraphicsObject did not receive Pan gesture
>>>>>>>>>> events
>>>>>>>>>> (only the "start" event, but never the "update" or "end" events).
>>>>>>>>>> Never
>>>>>>>>>> tried "Tab" events, but I got "pinch" (zoom/rotate) to work.
>>>>>>>>>>
>>>>>>>>>> But just now I am investigating another issue: it seems that the
>>>>>>>>>> value of
>>>>>>>>>>
>>>>>>>>>>  http://doc.trolltech.com/4.7/qpinchgesture.html#scaleFactor-prop
>>>>>>>>>>
>>>>>>>>>> returns different signed values on Mac and Windows 7. I developped
>>>>>>>>>> my
>>>>>>>>>> app on Mac and implemented my "zoom" in such a way that when
>>>>>>>>>> moving the
>>>>>>>>>> fingers apart the object would get bigger.
>>>>>>>>>>
>>>>>>>>>> A quick test on some netbook and laptop running Windows 7 revealed
>>>>>>>>>> that
>>>>>>>>>> the "zoom" would work the other way (the object was scaled down
>>>>>>>>>> instead
>>>>>>>>>> of scaled up). So I assume it is the sign which is different on
>>>>>>>>>> Mac and
>>>>>>>>>> Windows 7 (= bug). But again, I did not have the opportunity yet
>>>>>>>>>> to
>>>>>>>>>> reproduce this behaviour with debugging possibilities.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Hope that gives you some pointers,
>>>>>>>>>>   Oliver
>>>>>>>>>> _______________________________________________
>>>>>>>>>> Qt-interest mailing list
>>>>>>>>>> Qt-interest at qt.nokia.com
>>>>>>>>>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> Qt-interest mailing list
>>>>>>>>> Qt-interest at qt.nokia.com
>>>>>>>>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110314/e65c076a/attachment.html 


More information about the Qt-interest-old mailing list