I just started learning QT in the past week or so and I am an experienced programmer (java, c++, scripting, etc). I've looked through much of the documentation on the graphics view framework including the examples. Since I still did not completely understand, I took the mouse collision demo and started playing with it. What I want to do is restrict the scene to one mouse and be able to control that mouse with the arrow keys.

I'm calling

Qt Code:
  1. this->setFlag(ItemIsFocusable,true);
To copy to clipboard, switch view to plain text mode 

In the constructor of my item. I also thought that I could call

Qt Code:
  1. this->setFocus()
To copy to clipboard, switch view to plain text mode 

to get the focus for that item too - but my item is not yet visible when it is being constructed (it hasn't even been added to the scene yet!).

I got around this by utilizing the timerEvent, calling setFocus in there, and then it will accept keyPressEvent - but I don't want to do that! Thats crazy talk!

What is the correct way to handle this so that I can give my item focus after being added to the scene?

Do I do something like this?

Qt Code:
  1. void MyScene::keyPressEvent(QKeyEvent *event)
  2. {
  3. printf("scene pressed!!!\n");
  4. QList<QGraphicsItem *> myItems = items();
  5. foreach (QGraphicsItem *item, myItems)
  6. {
  7. item->setFocus();
  8. }
  9. }
To copy to clipboard, switch view to plain text mode 

And then somehow pass on the event to my item? Any thoughts would be appreciated!