I've solved it. I had to implement QEvent::FocusOut and QEvent::FocusIn events