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
Re: QGraphicsItem keyPressEvent oddness
Do you call the base class implementation in your handlers?
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.
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
Code:
qApp->installEventFilter(this);
bool MainWidgetThatContainsGrphViewAndItems
::eventFilter(QObject* o,
QEvent* e
) {
if(e
->type
()==QEvent::KeyPress) {
qWarning()<<"The bad guy which steals the keyevent is"<<o;
}
return false;
}
easy!!
edit: do tell us who was stealing.;)
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. :o
Re: QGraphicsItem keyPressEvent oddness
Quote:
Originally Posted by
MrDeath
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
Code:
qApp->installEventFilter(this);
bool MainWidgetThatContainsGrphViewAndItems
::eventFilter(QObject* o,
QEvent* e
) {
if(e
->type
()==QEvent::KeyPress) {
qWarning()<<"The bad guy which steals the keyevent is"<<o;
}
return false;
}
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!