get notified when QDockWidget gets/looses focus?
hi,
I have a QMainWindow hosting several subclassed QDockWidgets. I would now need to detect when one of the QDockWIdgets gets or looses focus.
There doesnt appear to be a signal for that, so i figured i have to catch the event somehow :
Code:
{
Q_OBJECT
public:
....
//qt event handlers
};
But the focusInEvent() never gets called. I am also worried that QDockWidget has or will have use for focusInEvent() itself, and i break its functionality.
How to do it properly?
Re: get notified when QDockWidget gets/looses focus?
The focusInEvent() occurs only when the widget has a focus policy set. You need to call the QWidget::setFocusPolicy() for the widget. Use Qt::StrongFocus if you want both keyboard and click focus events.
By default, QWidget has Qt::NoFocus, which means they do not receive focus events, so that's why you aren't seeing them.
If you need your dock widget to tell other widgets that it has received (or lost) focus, use the event handlers to emit signals. If you want to be sure that you are not interfering with normal widget behavior, call the base class handler (or simply don't set the event's "accepted" parameter to true).