I am making a simple game with Qt, and I would like to pause the game when the user switches to another window (this could be minimizing or accidentally clicking on the window next to it, etc.). My game is wrapped in QMainWindow, so I would like to know when it will lose focus.
I tried several different methods for this, but I was not successful. I first tried to overload QMainWindow focusOutEvent, but this method was only called when I first gave window focus using setFocus. I also tried to overload the window event (QEvent *) method to check QEvent :: ApplicationActive and QEvent :: ApplicationDeactivate.
I would publish the code for my QMainWindow, but so far not much to show, I literally just tried to implement these two methods, but not one of them was called. I did nothing else to set up these methods (maybe I am missing a step?).
Does anyone know a good way to determine if your QMainWindow has βlost focusβ?
source share