I am writing on QT. OpenGL is connected, work properly, but the events and keyPressEvent mousePressEvent not respond to keystrokes.
class MainWindow : public QGLWidget
{
Q_OBJECT
protected:
void initializeGL(); // Метод для инициализирования opengl
void resizeGL(int nWidth, int nHeight); // Метод вызываемый после каждого изменения размера окна
void paintGL(); // Метод для вывода изображения на экран
void paintSun();
void mousePressEvent(QMouseEvent *mouse);
void keyPressEvent(QKeyEvent *ke);
public:
MainWindow(int x, int y,QWidget *parent = 0);
~MainWindow();
};
void MainWindow::keyPressEvent(QKeyEvent *ke)
{
switch (ke->key())
{
case Qt::Key_Space://NO REACTION
View += 1;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
paintPlanet();
break;
}
updateGL();
}
Make sure that the MainWindow accepts Focus by setting
Also you should call the base implementation of QWidget::keyPressEvent
as stated here. Is there another Widget which has the focus and does not pass the KeyEvent?