PDA

View Full Version : keyReleaseEvent not called



EarthHobbit
19th April 2015, 09:33
Hi,
I have a custom QGraphicsTextItem with a keyReleaseEvent, but this event is never called when I release a key.
This is the way I create my custom QGraphicsItem:

CustomQGraphicsTextItemClass *oneTextNode=new CustomQGraphicsTextItemClass();
scene()->addItem(oneTextNode);
oneTextNode->setFlags(QGraphicsItem::ItemIsFocusable);
oneTextNode->setFocus();

and my custom QGraphicsItem constructor has this command:

setTextInteractionFlags(Qt::TextEditorInteraction) ;

The release code is the following:

void CustomQGraphicsTextItemClass::keyReleaseEvent(QKey Event *e)
{
MGlobal::displayInfo(MQtUtil::toMString(QString(). sprintf("Release !!!!!!!")));
}

The Release function is never called. There is a keyPressEvent too, but this one gets properly called.

Thanks for your help.

Lykurg
19th April 2015, 16:02
Can't test it right now, but when I remember right, you have to grab the keyboard first to receive key events: QGraphicsItem::grabKeyboard().