Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Gestures and QGraphicsScene

  1. #1
    Join Date
    Jun 2009
    Posts
    25
    Thanks
    1

    Default Gestures and QGraphicsScene

    Hello,
    I want to use gesture framework, but at the begining I have some problems.
    I have QGraphicsView and QGraphicsScene
    view->addScene(myScene);
    At the myScene threre are few icons(QPixmapItem) . I try recognize QSwipeGesture( click somewhere on gaphicsScene and drag) and after recognizon start some animation (QtKinetic)
    I have done:
    Qt Code:
    1. view->grabGesture(Qt::SwipeGesture);
    To copy to clipboard, switch view to plain text mode 
    I had hoepe that event would propagate to QGraphicsScene and i have done in myScene
    Qt Code:
    1. virtual bool myScene::event(QEvent *event)
    2. {
    3. if (event->type() == QEvent::Gesture)
    4. do something
    5. return QGraphicsScene::event(event);
    6. }
    To copy to clipboard, switch view to plain text mode 
    unfortunaltely program does not go to line "do something".
    What I do wrong??

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Gestures and QGraphicsScene

    First of all you should be grabbing the gesture on the view's viewport, not on the view itself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2009
    Posts
    25
    Thanks
    1

    Default Re: Gestures and QGraphicsScene

    I modified my code. Now I run grab gestures on viewport and I try to catch QGesture event on object that inherits QGraphicsObject. Unfortunatelly it seems that there doesn't apper any gestureEvent. I have code everithing similar to example given by Qt.
    I found the same problem in this and another forum, but there isn't any solve. So maybe is here anyone who menage to run application witch QGestures?

  4. #4
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Gestures and QGraphicsScene

    I have the same problem. I can get QGestureEvents from the Viewport but not from a QGraphicsObject. The just do not seem to be there. Anyone know why?

    Here is a example of what I am trying.
    Qt Code:
    1. class GestureTest : QGraphicsObject {
    2. Q_OBJECT
    3.  
    4. public:
    5.  
    6. GestureTest() {
    7. grabGesture(Qt::PinchGesture);
    8. }
    9.  
    10. bool sceneEvent(QEvent* pEvent) {
    11.  
    12. if (pEvent->type() == QEvent::Gesture) {
    13. std::cout << "Gesture Received!" << std::endl;
    14. }
    15.  
    16. return QGraphicsObject::sceneEvent(pEvent);
    17. }
    18. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by stretchtiberius; 16th June 2010 at 20:39. Reason: spelling corrections

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Gestures and QGraphicsScene

    I would assume gesture events might not be propagated to items. It's still a new api in Qt, it might not be complete.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Gestures and QGraphicsScene

    I would assume gesture events might not be propagated to items.
    That could be the case. However, QGraphicsObject has a grabGesture() function. Therefore, there must be a way to make the gesture events propagate. Unless the planned API is not fully implemented.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Gestures and QGraphicsScene

    Quote Originally Posted by stretchtiberius View Post
    Unless the planned API is not fully implemented.
    That might be the case. Maybe you should try some Qt 4.7 snapshot.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Gestures and QGraphicsScene

    Sorry for disturbing, but I tried gesture recognition without success as well: is gesture classes only supported by some platforms or are all platforms supported?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Gestures and QGraphicsScene

    Quote Originally Posted by wysota View Post
    That might be the case. Maybe you should try some Qt 4.7 snapshot.
    The docs in 4.6 seem to suggest gestures work for graphic view's objects too.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: Gestures and QGraphicsScene

    is gesture classes only supported by some platforms or are all platforms supported?
    From what I understand, multi-touch gestures are only supported on some platforms such as Windows 7.

    The docs in 4.6 seem to suggest gestures work for graphic view's objects too.
    That is what confuses me. I am using Qt 4.6.3 and yet I get no QGestureEvents from my QGraphicsObject.

    Here is a full QGraphicsObject to test gestures with. Take a look and see if I am missing something. If someone else could test test it themselves that would be great! I just added it to a standard QGraphicsScene. I am compiling 4.7 beta now and will give that a try.

    Qt Code:
    1. #ifndef ___TOUCHOBJECT___
    2. #define ___TOUCHOBJECT___
    3.  
    4. #include <QtGui>
    5. #include <iostream>
    6.  
    7. class TouchObject : public QGraphicsObject {
    8. Q_OBJECT
    9. public:
    10. TouchObject(QGraphicsItem* pParent = NULL) : QGraphicsObject(pParent) {
    11. grabGesture(Qt::PinchGesture);
    12. grabGesture(Qt::PanGesture);
    13. grabGesture(Qt::SwipeGesture);
    14. }
    15.  
    16. QRectF boundingRect() const {
    17. return QRectF(-WIDTH / 2, -HEIGHT / 2, WIDTH, HEIGHT);
    18. }
    19.  
    20. QPainterPath shape() const {
    21. path.addEllipse(boundingRect());
    22. return path;
    23. }
    24.  
    25. void paint(QPainter *painter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget) {
    26. pOption;
    27. pWidget;
    28. painter->setBrush(Qt::blue);
    29. painter->drawEllipse(boundingRect());
    30. }
    31.  
    32. bool sceneEvent(QEvent* pEvent) {
    33. case QEvent::Gesture:
    34. std::cout << "Gesture Event Received from sceneEvent()" << std::endl;
    35. }
    36.  
    37. return QGraphicsObject::sceneEvent(pEvent);
    38. }
    39.  
    40. bool event(QEvent* pEvent) {
    41. switch (pEvent->type()) {
    42. case QEvent::Gesture:
    43. std::cout << "Gesture Event Received from event()" << std::endl;
    44. }
    45.  
    46. return QGraphicsObject::event(pEvent);
    47. }
    48.  
    49. private:
    50. static const int WIDTH = 80;
    51. static const int HEIGHT = 80;
    52. };
    53.  
    54. #endif
    To copy to clipboard, switch view to plain text mode 
    Last edited by stretchtiberius; 17th June 2010 at 19:20. Reason: add #define to code

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Gestures and QGraphicsScene

    Pan and swipe gestures don't require multi-touch.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: Gestures and QGraphicsScene

    I just tested using QGraphicObject with Qt 4.7.0 beta 1. Still did not work. I am beginning to think that this might be a complete oversight by the Qt developers. Maybe passing gesture events to a QGraphicsObject is unknowingly unfinished.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Gestures and QGraphicsScene

    Do gesture-related examples bundled with Qt work for you?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Gestures and QGraphicsScene

    Do gesture-related examples bundled with Qt work for you?
    Yes the gesture example and the multi-touch examples work. However, there is no example that has a QGraphicsObject receive gestures. I think this is a major oversight.

  15. #15
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Re: Gestures and QGraphicsScene

    After playing with it for a little longer I made some interesting observations. If I do not call setAcceptTouchEvents(true) none of the QGestureRecognizers receive any QTouchEvents. If I call setAcceptTouchEvents(true) from my QGraphicsObject, the appropriate QGestureRecognizer class receives events of type QEvent::TouchBegin. However, it never receives any TouchUpdate or TouchEnd events. Because most of the recognition is in TouchUpdate none of the gestures are recognized and therefore, no QGestureEvents are created. I have no idea how to get around this problem.

    Thanks for you help.

  16. #16
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: Gestures and QGraphicsScene

    After getting some help by sending a message to the qt4-preview-feedback@trolltech.com, I learned that you have to call setAcceptTouchEvents(true) and in the sceneEvent() acccept TouchStartedEvents and call grabGesture on the viewport as well as within the QGraphicObject. With all this you still cannot receive QPanEvents (likely because the hotspot is not defined in QPanGestureRecognizer). Here is my previous example with the necessary changes.

    Within the GraphicsView
    Qt Code:
    1. viewport()->grabGesture(Qt::PinchGesture);
    To copy to clipboard, switch view to plain text mode 

    TouchObject.h
    Qt Code:
    1. #ifndef ___TOUCHOBJECT___
    2. #define ___TOUCHOBJECT___
    3.  
    4. #include <QtGui>
    5. #include <QGesture>
    6. #include <iostream>
    7.  
    8. class TouchObject : public QGraphicsObject {
    9. Q_OBJECT
    10. public:
    11. TouchObject(QGraphicsItem* pParent = NULL) : QGraphicsObject(pParent) {
    12.  
    13. grabGesture(Qt::PinchGesture);
    14. setAcceptTouchEvents(true);
    15. }
    16.  
    17. QRectF boundingRect() const {
    18. return QRectF(-WIDTH / 2, -HEIGHT / 2, WIDTH, HEIGHT);
    19. }
    20.  
    21. QPainterPath shape() const {
    22. path.addEllipse(boundingRect());
    23. return path;
    24. }
    25.  
    26. void paint(QPainter *painter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget) {
    27. pOption;
    28. pWidget;
    29. painter->setBrush(Qt::blue);
    30. painter->drawEllipse(boundingRect());
    31. }
    32.  
    33.  
    34. bool sceneEvent(QEvent* pEvent) {
    35. switch (pEvent->type()) {
    36. case QEvent::TouchBegin:
    37. pEvent->accept();
    38. return true;
    39. case QEvent::Gesture:
    40. std::cout << "Gesture Event Received from sceneEvent()";
    41. QGestureEvent* pGestureEvent = static_cast<QGestureEvent*>(pEvent);
    42. if(QGesture *pinch = pGestureEvent->gesture(Qt::PinchGesture)) {
    43. std::cout << " Pinch Gesture" << std::endl;
    44. }
    45. else {
    46. std::cout << " not a pinch gesture." << std::endl;
    47. }
    48. break;
    49. }
    50.  
    51. return QGraphicsObject::sceneEvent(pEvent);
    52. }
    53.  
    54. private:
    55. static const int WIDTH = 160;
    56. static const int HEIGHT = 160;
    57. };
    58.  
    59. #endif
    To copy to clipboard, switch view to plain text mode 

    I hope they fix these problems in Qt 4.7 and the documentation improves. Thank you for your help.

  17. #17
    Join Date
    Jan 2011
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Gestures and QGraphicsScene

    Did you try this example with Qt 4.7.1? This still does not seem to work for me:

    - My QGraphicsView also grabs the Gestures in question
    - in my QGraphicsObject subclasss I grab the same Gestures
    - in my QGraphicsObject subclass I do call setAcceptTouchEvents(true)
    - my boundingRect() method returns some ridiculous large rectangle (for testing)
    - I do get the QEvent::TouchBegin and I accept this event as suggested, but...
    - I still never get the desired QEvent::Gesture in QGraphicsObject#sceneEvent(QEvent *) method

    However I do get Gesture events in my QGraphicsScene as expected. Unfortunately it seems that Pan events are "swallowed" when the mouse hovers over any item in the scene, see http://bugreports.qt.nokia.com/browse/QTBUG-16281

    That's why my idea was to create an "invisible" (note: I do not call setVisible(false) on my QGraphicsObject item - in fact in my attempt I actually draw some rectangle, to make really sure the object is in the scene!) QGraphicsObject based "Gesture Controller", which would act as an event filter on all items added to the scene.


    That is on a MacBook Pro running OS X 10.6.5. As I said, I do get Gesture events inside my QGraphicsScene (off course I disabled that code while testing my QGraphicsObject approach), so Gestures are definitelly supported on my platform.

    Can anyone confirm whether you have a running example using Qt 4.7.1 and receive Gestures inside a QGraphicsObject based item in a QGraphicsScene?

    Thanks, Oliver

  18. #18
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Gestures and QGraphicsScene

    Yes, I am using something similar in my code and it is still working with Qt 4.7.1. I'll double check this example tomorrow after work and let you know if I made any changes.

  19. #19
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: Gestures and QGraphicsScene

    I confirmed that the code I posted previously (the TouchObject class) still receives gesture events with Qt 4.7.1 under Windows 7. I cannot test for OS X. However, I will attach the other little code pieces I use to get it running. I hope it helps. Let me know if I can do anything else for you.

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include <QGraphicsView>
    3. #include <QGraphicsScene>
    4. #include "TouchObject.h"
    5.  
    6. int main(int argc, char* argv[]){
    7.  
    8. QApplication app(argc, argv);
    9. QGraphicsScene* pScene = new QGraphicsScene();
    10. pScene->setSceneRect(-300, -300, 600, 600);
    11. pScene->addItem(new TouchObject());
    12. QGraphicsView view(pScene);
    13.  
    14. view.show();
    15.  
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

    .pro file
    Qt Code:
    1. TEMPLATE = app
    2. CONFIG += qt warn_on no_keywords embed_manifest_exe
    3. QT +=
    4. TARGET = GraphicsObjectGestures
    5. SOURCES = main.cpp
    6. HEADERS = TouchObject.h
    7. LIBS +=
    8. CONFIG += console
    9.  
    10. # Treat warnings as errors
    11. win32:QMAKE_CXXFLAGS += /WX
    To copy to clipboard, switch view to plain text mode 

    TouchObject.h is the same as before.

  20. #20
    Join Date
    Jan 2011
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Gestures and QGraphicsScene

    Quote Originally Posted by stretchtiberius View Post
    I confirmed that the code I posted previously (the TouchObject class) still receives gesture events with Qt 4.7.1 under Windows 7. I cannot test for OS X. However, I will attach the other little code pieces I use to get it running. I hope it helps. Let me know if I can do anything else for you.
    ...
    Thanks, I will stich your example together and try it out on Mac OS X and post my results here.

    By the way - on a slightly different topic, "Gesture Pan Events swallowed" - does the example work for you on Windows 7: http://bugreports.qt.nokia.com/secur...iewGesture.zip

    It seems that when the mouse cursor is placed over an item the "Pan" gesture gets "swallowed", only the gesture "Begin" event is delivered to the QGraphicsScene. Pinch events always work, regardless of where the mouse is placed.

    Note that in the example you would only get debug output, and the mouse cursor changes to a cross in case of Pan events. And the cursor remains a cross when the mouse cursor was placed over an item (because no "End" Gesture event is received).


    If that example worked for you on Windows 7 then I am facing a Mac OS X Cocoa specific issue (on a MacBook Pro).

    Thanks!
    Oliver
    Last edited by Oliver Knoll; 10th January 2011 at 09:57.

Similar Threads

  1. Qt gestures on PC
    By pingwinek in forum Qt Programming
    Replies: 10
    Last Post: 1st December 2010, 02:30
  2. Image Gestures example on OSX 10.5.8
    By jhndnn in forum Qt Programming
    Replies: 2
    Last Post: 17th September 2010, 12:55
  3. Grabing Touch Gestures on GraphicsView with Qt 4.6
    By serge in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2010, 23:50
  4. Gestures
    By emrares in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 20th December 2009, 09:30
  5. in QGraphicsScene matrix of other QGraphicsScene
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2009, 17:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.