PDA

View Full Version : Key event not receiving from QGraphicsRectItem



sandeep93
2nd March 2019, 12:29
Hi i am new to Qt,

i have added a rect of QGraphicsRectItem and added a member function
void MyRect::keyPressEvent(QKeyEvent *event)
{
qDebug() << "MyRect knows that you pressed a key";
}

I have set the flags as well like below
rect->setFlag(QGraphicsItem::ItemIsFocusable,true);
rect->setFocus();

but still when i am clicking on the rectangle, i am not able to see the o/p on console log.
please can any help me out.

anda_skoa
2nd March 2019, 14:30
Is the QGraphicsView or its viewport() the application's focusWidget() ?

Cheers,
_