Good morning to all, this is my scenario:
I wrote an application based on QMainWindow containing a centralwidget.
The centralwidget contains 2 classes inherited from QWidget lets say ww1 and ww2.
Now I would, pressing tab, move the focus between ww1 and ww2.
I tried to override the focusInEvent - focusOutEvent methods of every QWidget
Qt Code:
  1. class MyWidget : public QWidget
  2. {
  3. //code
  4. protected:
  5. virtual void focusInEvent( QFocusEvent* event );
  6. virtual void focusOutEvent( QFocusEvent* event );
  7. //more code
  8. };
To copy to clipboard, switch view to plain text mode 
Now I would, from the QMainWindow, to execute some code depending on the QWidget having the focus. Now I emit a signal in the focusIn/Out methods so:

Qt Code:
  1. /*********************************************/
  2. /* focusInEvent
  3. /*********************************************/
  4. void MyWidget::focusInEvent( QFocusEvent *event )
  5. {
  6. Q_UNUSED(event);
  7. emit sig_focusIn(); // widget had the focus
  8. }
  9.  
  10. /*********************************************/
  11. /* focusOutEvent
  12. /*********************************************/
  13. void MyWidget::focusOutEvent( QFocusEvent *event )
  14. {
  15. Q_UNUSED(event);
  16. emit sig_focusOut(); // focus is gone
  17. }
To copy to clipboard, switch view to plain text mode 
The signals are connected to a slot that's part of mainwindow class. My code works but I'm not sure if is the best way to achieve what I would.
For example I read about a virtual bool eventFilter(QObject *obj, QEvent *evt); that can filter ( as it says ) the event sent to other widgets. For example intercepting the focus event. The problem is how can I know it the focus is for ww1 or ww2?
I hope to get a reply.
Best Regards,
Franco