Results 1 to 6 of 6

Thread: QGraphicsItem keyPressEvent oddness

  1. #1
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QGraphicsItem keyPressEvent oddness

    I'm new to Qt so please be kind!

    I've overridden QGraphicsItem::keyPressEvent, focusInEvent and focusOutEvent and set QGraphicsItem::ItemIsFocusable in my QGraphicsItem's constructor.

    My objects now receive focusInEvent and focusOutEvent events, but not keyPressEvent.
    My scene does not have a keyPressEvent handler, so I know it is not blocking this event from reach my objects.

    My project at this stage is too large to post and annoyingly, when I created a minimal project to try to reproduce the problem, keyPressEvent is always received correctly!

    What could be blocking keyPressEvent events from getting to my QGraphicsItems?

    - I could restart my project putting it back together line by line/function by function (it's about 2000 lines so I'm at the point where doing so will be really annoying). But before I do, if anyone knows of any obvious gotchas that immediately come to mind it would be very muchly appreciated.

    Thanks
    J

  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: QGraphicsItem keyPressEvent oddness

    Do you call the base class implementation in your handlers?
    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. The following user says thank you to wysota for this useful post:

    jonks (3rd June 2009)

  4. #3
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QGraphicsItem keyPressEvent oddness

    If you mean in focusInEvent, focusOutEvent and keyPressEvent? - then yes.

    In my scene I've also just removed all functions and overrides that may affect focus (mouse event handers etc)...but no joy.

  5. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsItem keyPressEvent oddness

    you dont have to tear apart your code to search for keyevent.
    just put eventFilter() in your main widget. and see where the keys are going

    Qt Code:
    1. qApp->installEventFilter(this);
    2. bool MainWidgetThatContainsGrphViewAndItems::eventFilter(QObject* o,QEvent* e)
    3. {
    4. if(e->type()==QEvent::KeyPress)
    5. {
    6. qWarning()<<"The bad guy which steals the keyevent is"<<o;
    7. }
    8. return false;
    9. }
    To copy to clipboard, switch view to plain text mode 

    easy!!

    edit: do tell us who was stealing.
    Last edited by nish; 3rd June 2009 at 07:36.

  6. The following 2 users say thank you to nish for this useful post:

    jonks (3rd June 2009), Seishin (15th November 2012)

  7. #5
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Thumbs up Re: QGraphicsItem keyPressEvent oddness

    Mr Death - that was pure genius!

    I subclassed QGraphicsView and put a keypress handler in there to reset zoom, and forgot to call the base class implementation.

  8. #6
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem keyPressEvent oddness

    Quote Originally Posted by MrDeath View Post
    you dont have to tear apart your code to search for keyevent.
    just put eventFilter() in your main widget. and see where the keys are going

    Qt Code:
    1. qApp->installEventFilter(this);
    2. bool MainWidgetThatContainsGrphViewAndItems::eventFilter(QObject* o,QEvent* e)
    3. {
    4. if(e->type()==QEvent::KeyPress)
    5. {
    6. qWarning()<<"The bad guy which steals the keyevent is"<<o;
    7. }
    8. return false;
    9. }
    To copy to clipboard, switch view to plain text mode 

    easy!!

    edit: do tell us who was stealing.
    Just by browsing the thread can teach me a lot even though I don't need it now

    Thanks!

Similar Threads

  1. QGraphicsItem doesn't inherit QObject?
    By xyzt in forum Qt Programming
    Replies: 6
    Last Post: 26th September 2011, 14:59
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. Replies: 1
    Last Post: 25th February 2009, 00:34
  4. keyPressEvent issue
    By oguzy in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2008, 15:39
  5. Snap-to grid on QGraphicsItem
    By hardgeus in forum Qt Programming
    Replies: 9
    Last Post: 28th April 2008, 16:22

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.