[Qt-interest] QGraphicsScene and multitouch events

Sean Hayes sean.t.hayes at vanderbilt.edu
Tue Jan 4 21:11:59 CET 2011


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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110104/324ca043/attachment.html 


More information about the Qt-interest-old mailing list