Anyway solved it. I needed to call grabKeyboard function from the MainWindow class, so this->grabKeyboard() is the line I needed to add when key_0 button is pressed so that MainWindow doesn't lose the keyboard focus, and then when released I needed to add the line this->releaseKeyboard() to resume normal behaviour, that is, other widgets can have the keyboard focus.
You need to accept the event so the parent knows that the event has been handled. Otherwise the event will go all children until someone accepts it or if none do, it will be ignored.
so keyEv->accept() should do the trick.
Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.