-1

I'm currently making an AI to "Snake". After adding QPushButton to my QMainWindow there is no response from window for pressing any key.

void MainWindow::keyReleaseEvent(QKeyEvent* event)
{
   g->key_event(event);
}

That's how I'm injecting QKeyEvent into my game class. Everything works without any QPushButton.

Murphy
  • 3,827
  • 4
  • 21
  • 35
  • 2
    The button might have the focus and therefore receive the events. – SteakOverflow Feb 09 '18 at 13:47
  • http://idownvotedbecau.se/nomcve/, and from your description it's rather hard to understand what is not working, and what you expect. Please take the [tour](https://stackoverflow.com/tour) and read [ask] first, then improve your question to increase your chances of getting useful answers. – Murphy Feb 09 '18 at 16:40

1 Answers1

0

It could be that the problem is related to your override method not passing the call up to the superclass. You might want to do it like this, instead:

void MainWindow::keyReleaseEvent(QKeyEvent* event)
{
    QMainWindow::keyReleaseEvent(event);
    g->key_event(event);
}
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234