[Qt-interest] QGraphicsScene and multitouch events

Luiz Geovani Vier lgvier at gmail.com
Wed Jan 12 14:28:33 CET 2011


Hello Devendra,

Since you are not using gestures, maybe you could try to unregister the
recognizers:

QGestureRecognizer::unregisterRecognizer(Qt::PanGesture);
QGestureRecognizer::unregisterRecognizer(Qt::SwipeGesture);
QGestureRecognizer::unregisterRecognizer(Qt::PinchGesture);

It seems the standard gesture recognizers are not able to dispatch the
events to multiple items on a scene simultaneously... Maybe that's
interfering with your touch events.

Also, try to accept the touch begin events

Good luck..
-Geovani


On Wed, Jan 12, 2011 at 5:38 AM, Devendra Patel <devpatel82 at gmail.com>wrote:

>
> Hi Sean,
>
> I tried your suggestion but am facing some issues.
>
> Firstly I am interested in raw touch events, not gestures. My goal is to
> place two dials in QGraphicsView and rotate them simultaneously using
> Multi-touch monitor. I am using Win 7 and Qt 4.7.
>
> I wrote following code to see if I can rotate two dials simultaneously. I
> can only rotate one dial simultaneously. I am able to rotate two dials
> simultaneously if I place them on QWidget rather than
> QGraphicsScene/QGraphicsView.
>
>
> int main(int argc, char **argv)
> {
>      QApplication app(argc, argv);
>      QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
> // just make sure that native widgets are not created
>      WCScene scene; //WCScene is derived from QGraphicsScene
>
>      CKnob dial,dial1; //CKnob is derived from QDial
>      dial.setGeometry(10,10,200,200);
>      dial1.setGeometry(210,10,200,200);
>
>      dial.setObjectName("1");
>      dial1.setObjectName("2");
>      dial.setAttribute(Qt::WA_AcceptTouchEvents);
>      dial1.setAttribute(Qt::WA_AcceptTouchEvents);
>
>      GraphicsView view(&scene); //GraphicsView derived from QGraphicsView
>      scene.addWidget(&dial);
>      scene.addWidget(&dial1);
>
>      view.setAttribute((Qt::WA_AcceptTouchEvents));
>      view.viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
>      view.show();
>      return app.exec();
> }
>
> In all the custom classes I am handling events and print message. Below is
> how I handle TouchBegin event in CKnob class.
>
>  switch(e->type())
>     {
>     case QEvent::TouchBegin:
>         qDebug("CKnob  QEvent::TouchBegin");
>         return QDial::event(e);
>     }
>
> All the Mouse and Touch events are handled similarly in custom classes. In
> GraphicsView I am overriding both viewportEvent(QEvent* ) and event(QEvent*)
> to print messages.
>
> This is What I see when I try to rotate the dials.
>
> GraphicsView viewportEvent::TouchBegin
> SCene QEvent::TouchBegin
> GraphicsView QEvent::TouchBegin
> GraphicsView viewportEvent::MouseMove
> GraphicsView viewportEvent::MouseButtonPress
> CKnob  QEvent::MouseButtonPress
> GraphicsView viewportEvent::MouseMove
> CKnob  QEvent::MouseMove
> GraphicsView viewportEvent::MouseMove
> CKnob  QEvent::MouseMove
> GraphicsView viewportEvent::MouseMove
> CKnob  QEvent::MouseMove
> GraphicsView viewportEvent::MouseMove
> CKnob  QEvent::MouseMove
> GraphicsView viewportEvent::MouseMove
> CKnob  QEvent::MouseMove
> GraphicsView viewportEvent::MouseMove
> CKnob  QEvent::MouseMove
> GraphicsView viewportEvent::MouseButtonRelease
> CKnob  QEvent::MouseButtonRelease
>
> I am puzzled to why I don't receive touchUpdate and touchEnd events at all,
> neither in graphicsview, graphicsscene nor in CKnob.
> Is there something wrong in my setup?
>
> Thanks,
> Devendra
>
>
> 2011/1/5 Sean Hayes <sean.t.hayes at vanderbilt.edu>
>
>  To get gestures to work in a QGraphicsView (in the scene) you have to do
>> the following:
>>
>>    - In the QGraphicsView accept gestures on the viewport (e.g.,
>>    viewport()->grabGesture(Qt::PinchGesture);)
>>    - In the QGraphicsObjects (and/or the QWidget) accept touch events
>>    (i.e., setAcceptTouchEvents(true);), grab the gesture (e.g.,
>>    grabGesture(Qt::PinchGesture);).
>>    - Finally, in the event function (sceneEvent() for a QGraphicsObject and
>>    event() for a QWidget) accept the touch begin events. An example
>>    below:
>>
>> bool QMapTouchItem::sceneEvent(QEvent* pEvent) {
>> switch (pEvent->type()) {
>>  case QEvent::TouchBegin: // Needed to get around Qt bug
>> pEvent->accept();
>>  return true;
>> case QEvent::Gesture:
>>  // handle the gesture
>> }
>>
>> return QMapItem::sceneEvent(pEvent);
>> }
>>
>> You can also check out this forum post.
>> http://www.qtcentre.org/threads/31582-Gestures-and-QGraphicsScene?p=172577
>> .
>>
>> On Tue, Jan 4, 2011 at 12:00 AM, Abhishek <abhishekworld at gmail.com>wrote:
>>
>>> I think you should look at QGraphicsProxyWdiget that makes more sense in
>>> your case http://doc.qt.nokia.com/4.7-snapshot/qgraphicsproxywidget.html
>>>
>>> <http://doc.qt.nokia.com/4.7-snapshot/qgraphicsproxywidget.html>
>>>
>>>>
>>>>    1.
>>>>
>>>>
>>>>
>>>>    	QGraphicsView <http://doc.qt.nokia.com/latest/qgraphicsview.html> view(&scene);
>>>>
>>>>
>>>>
>>>>
>>>>    2.
>>>>    3.
>>>>
>>>>
>>>>
>>>>            QWidget <http://doc.qt.nokia.com/latest/qwidget.html>* widget=new QWidget <http://doc.qt.nokia.com/latest/qwidget.html>;
>>>>
>>>>
>>>>
>>>>    4.
>>>>    5.
>>>>
>>>>
>>>>
>>>>         scene.addWidget(widget);
>>>>    6.
>>>>
>>>>
>>>>
>>>>
>>>>    7.
>>>>
>>>>
>>>>
>>>>         view.setDragMode(QGraphicsView <http://doc.qt.nokia.com/latest/qgraphicsview.html>::ScrollHandDrag);
>>>>
>>>>
>>>>
>>>>
>>>>    8.
>>>>    9.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Abhishek Patil
>>> http://thezeroth.net
>>>
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at qt.nokia.com
>>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>>
>>>
>>
>
>
> --
> Blog
> http://observe-read-think.blogspot.com/
>
> _______________________________________________
> 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/20110112/cec601d0/attachment.html 


More information about the Qt-interest-old mailing list