[Qt-interest] QGraphicsScene and multitouch events

Sean Hayes sean.t.hayes at vanderbilt.edu
Wed Jan 12 15:04:32 CET 2011


Hello Devendra,

>
> 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.
>

While it is fine to use the raw touch events, it may be easier to use the
QPinchGesture. One of it's properties/functions is rotationAngle. That is
one less thing less you have to implement.


> 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);
>     }
>
Are you handling TouchUpdate and TouchEnd events in the same manner? Also,
if you using the event, I believe you should return true. Finally, you may
have to specifically accept the TouchBegin event (probably not but it is
worth a try). Something like the following.
bool MyDial::sceneEvent(QEvent * e) {
    switch(e->type()) {
        case QEvent::TouchBegin:
            qDebug("CKnob  QEvent::TouchBegin");
            e->accept();
            return true;
        case QEvent::TouchUpdate:
            qDebug("CKnob  QEvent::TouchUpdate");
            return true;
        case QEvent::TouchEnd:
            qDebug("CKnob  QEvent::TouchEnd");
            return true;
    }

    return QDial::event(e);
}

Let me know if any of that helps. I am not as experienced with raw touch
events.

Cheers,
Sean


On Wed, Jan 12, 2011 at 1: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/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110112/4d34b6c4/attachment.html 


More information about the Qt-interest-old mailing list