Home Ask Login Register

Developers Planet

Your answer is one click away!

MetalDiamond February 2016

Can't capture QkeyEvent in QopenGLWidget

I have a problem about capturing QKeyEvent in a QOpenGLWidget when I use it as a... widget. It works perfectly well if I use my QOpenGLWidget as a main window but not if the widget is the child of another mainWindow... (Nothing happen)

Maybe I messed up something about how Qt widgets works but I can't figure it out.

Thank you


floppy12 February 2016

I guess either your mainWindow treat the QKeyEvent (maybe it's an already mapped key combination) or prevents the forwarding to your custom widget component. Either when used as "QWidget", special rules are applied and you need to override some others handlers to make your handler able to take place.

ThorngardSO February 2016

Try calling yourGLWidget->setFocusPolicy (Qt::StrongFocus);

From http://doc.qt.io/qt-5/qwidget.html#focusPolicy-prop: "You must enable keyboard focus for a widget if it processes keyboard events. This is normally done from the widget's constructor."

Post Status

Asked in February 2016
Viewed 1,615 times
Voted 10
Answered 2 times


Leave an answer

Quote of the day: live life