[Qt-interest] QGraphicsScene and multitouch events
Devendra Patel
devpatel82 at gmail.com
Sun Jan 16 16:50:47 CET 2011
Hi Sean,
Yes I am handling TouchUpdate and TouchEnd events similarly.
I tried your suggestions but it didn't work. I get the same output as I said
in the previous email.
Well about using Raw touch events as to gestures, I think QGraphicsScene
will deliver the events to underlying widget (like QDial) and that should
interpret the event accordingly. I don't need any kind of gestures on a
single widget.
It seems that I will have to step into Qt code and see how QGraphicsSystem
handles multitouch events.
FYI: Qt has a bug in handling mutlti-touch events on different events on
Win7. You can find details here
http://bugreports.qt.nokia.com/browse/QTBUG-16035
On another note, the main reason for me to use QGraphicsSystem to display
widgets as to QMainWindow is to be able to zoom in and zoom out. Is there
another way using which I can zoom in / out of QMainWindow?
Thanks,
From: Sean Hayes [mailto:sean.t.hayes at vanderbilt.edu]
Sent: Wednesday, January 12, 2011 7:35 PM
To: Devendra Patel
Cc: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] QGraphicsScene and multitouch events
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
1.
2.
3.
4.
5.
6. QGraphicsView <http://doc.qt.nokia.com/latest/qgraphicsview.html>
view(&scene);
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18. QWidget <http://doc.qt.nokia.com/latest/qwidget.html> *
widget=new QWidget <http://doc.qt.nokia.com/latest/qwidget.html> ;
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29. scene.addWidget(widget);
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41. view.setDragMode(QGraphicsView
<http://doc.qt.nokia.com/latest/qgraphicsview.html> ::ScrollHandDrag);
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
--
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/20110116/95ad550d/attachment.html
More information about the Qt-interest-old
mailing list