Results 1 to 20 of 22

Thread: Gestures and QGraphicsScene

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.

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
  •  
Qt is a trademark of The Qt Company.