Results 1 to 2 of 2

Thread: keyPressEvent(QKeyEvent*) is not going to QGraphicsItem & going into infinite loop

  1. #1
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default keyPressEvent(QKeyEvent*) is not going to QGraphicsItem & going into infinite loop

    hi, i have to catch keyPressEvent(QKeyEvent* f_event) on item (derived from QGraphicsObject), i am not able to get the event in item, instead it is going into infinite loop in scene itself.
    below is the code, thanks in advance.

    Qt Code:
    1. //scene
    2. void MyScene::keyPressEvent(QKeyEvent* f_event)
    3. {
    4. if(item && item->isSelected())
    5. {
    6. switch (f_event->key())
    7. {
    8. case Qt::Key_Up:
    9. case Qt::Key_Down:
    10. case Qt::Key_Left:
    11. case Qt::Key_Right:
    12. Item->setFocus(); //i have set item is focusable flag in item constructor.
    13. QGraphicsScene::keyPressEvent(f_event); //here its going back to the MyScene::keyPressEvent(QKeyEvent* f_event)again & into infinite loop, Item::keyPressEvent(QKeyEvent* f_event) is not calling at all
    14. break;
    15. default:
    16. QGraphicsScene::keyPressEvent(f_event);
    17. }
    18. }
    19.  
    20. //item
    21.  
    22. class Item : public QGraphicsObject
    23. {
    24.  
    25. Q_OBJECT
    26. /////////////////......///////
    27.  
    28. protected:
    29. Q_DISABLE_COPY(Item);
    30.  
    31. void mousePressEvent(QGraphicsSceneMouseEvent * f_event);
    32. void mouseMoveEvent(QGraphicsSceneMouseEvent * f_event);
    33. void mouseReleaseEvent(QGraphicsSceneMouseEvent * f_event);
    34. void keyPressEvent(QKeyEvent* f_event);
    35. void contextMenuEvent(QGraphicsSceneContextMenuEvent * f_event);
    36. };
    37.  
    38. void Item::keyPressEvent(QKeyEvent* f_event)
    39. {
    40.  
    41. QGraphicsObject::keyPressEvent(f_event);
    42. //qDebug()<<"keyPressEvent";
    43. f_event->accept();
    44. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by prasad.ece2; 27th February 2014 at 06:12.

  2. #2
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: keyPressEvent(QKeyEvent*) is not going to QGraphicsItem & going into infinite loo

    can any one help me regarding this problem please...?

Similar Threads

  1. QThread : how to stop an infinite loop
    By TarielVincent in forum Qt Programming
    Replies: 9
    Last Post: 24th February 2012, 21:22
  2. Replies: 3
    Last Post: 4th October 2010, 15:39
  3. infinite loop
    By zakis in forum Qt Programming
    Replies: 1
    Last Post: 4th November 2009, 17:52
  4. QLineEdit and keyPressEvent(QKeyEvent *)
    By fear in forum Qt Programming
    Replies: 6
    Last Post: 3rd June 2008, 19:31
  5. QLineEdit & keyPressEvent(QKeyEvent *)
    By munna in forum Newbie
    Replies: 7
    Last Post: 29th March 2006, 14:50

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.