[Qt-interest] Key events not responding immediately

Patric userqt at gmail.com
Mon Aug 24 17:14:53 CEST 2009


Damn it, 
I found out that if I click on the item with my mouse it gets focus. It seems that my code that sets the focus on the item manually from the method is not working... 
I'm using this code : 

human= new Human();
human->setFlags(QGraphicsItem::ItemIsFocusable);

scene->addItem(human);

human->setFocus();



The idea is that on any turn different objects on the field should be focused. So when they are focused, we can't navigate them with the keys on the keyboard. 

Can someone tell me how can I do this ? 



It seems that QGraphicsItem::ItemIsFocusable is making the item focusable from the mouse... I don't want this to happen. I need my code to determine which object to be focused and to set the focus to this object manually. 



But from the documentation of QGraphicsItem::setFocus() : 

Only items that set the ItemIsFocusable flag can accept keyboard focus.





This sux. Does anyone know how I can set keyboard input to some item determined from my code ? 

Best regards, 
Patric
  ----- Original Message ----- 
  From: Patric 
  To: qt-interest at trolltech.com 
  Sent: Monday, August 24, 2009 5:54 PM
  Subject: Key events not responding immediately


  Hello, 
  I have a strange problem here. 
  I'm experiencing a delay with the key press events... 

  I have a QGraphicsView and 3 items ( classes that inherit QGraphicsPixmapItem ). 

  It's a game actually. A simple board, characters on it, turn based. 
  So when I add only one character to the board ( scene ), everything is fine and there is no such delay in pressing keys (and when key is pressed the character should move). 

  But when I add more than one objects in there, start new game (and my program places the three objects randomly on the field) I have to wait approximately 5 seconds before pressing a key. 
  Because before that my game just not respond to my key press events.. 

  Any ideas where might be the problem ?

  Regards, 
  Patric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090824/d213ccd1/attachment.html 


More information about the Qt-interest-old mailing list