Unsolved QGraphicsScene does not receive keyPressEvent
-
QGraphicsScene does not receive keyPressEvent. How to fix it?
-
Can you please be a little bit more precise on your problem and what you are trying to do? A scene is no widget nor does display anything so how should it receive a key event?
-
@clostridium_difficile
Google for:QGraphicsScene does not receive keyPressEvent
Assuming you are meaning a
QGraphicsView
, there are plenty of examples. Maybe this one in our forum:
https://forum.qt.io/topic/74169/capturing-key-press-in-qgraphicsview-within-main-function -
QGraphicsScene receives mouse events, but does not receive key press events? I want rotate some items in scene, once key is pressed.
-
@clostridium_difficile
Let's start again. There is https://doc.qt.io/qt-5/qgraphicsscene.html#keyPressEventThis event handler, for event keyEvent, can be reimplemented in a subclass to receive keypress events. The default implementation forwards the event to current focus item.
There is also https://doc.qt.io/qt-5/qgraphicsview.html#keyPressEvent
Reimplements: QAbstractScrollArea::keyPressEvent(QKeyEvent *e).
What is not working for you?
A scene is no widget nor does display anything so how should it receive a key event?
I thought the same as you initially, yet nonetheless there is https://doc.qt.io/qt-5/qgraphicsscene.html#keyPressEvent, and similar for mousey events?