问题
I converted my Qt application from Qt 5.3 to 5.6. Previously I used to use QGLWidget and now upgraded to QOpenGLWindow contained in a QWidget. I would like my window to handle some key press events. QOpenGLWindow does have protected methods to handle the keyboard events. However, as opposed to the old QGLWidget, it does not have setFocus() method and my handlers are not being called. What is the remedy? Even when I tried to resort to setting focus to the owning container then manually piping events to QOpenGLWindow, no events seem to come.
回答1:
I managed to solve the problem by adding eventFilter to my subclass of QOpenGLWindow and then installing event filter for the owning container (and some of its parents).
来源:https://stackoverflow.com/questions/37196155/how-to-direct-keyboard-input-qopenglwindow-in-5-6