3

With a complex layout, what would the easies way be to get a signal to a parent QWidget if a child has got focus?

One idea would be to somehow install event filters on all child QWidgets, but that seems somewhat silly.

Doesn't a parent QWidget really just somehow know that one of it's children has the focus?

EDIT: Found this, maybe it's the only way then

How to change a parent widget's background when a child widget has focus?

Community
  • 1
  • 1
0xbaadf00d
  • 2,535
  • 2
  • 24
  • 46

2 Answers2

3

You can install event filter for all necessary childs (is is OK), or override QWidget::focusInEvent for each child that needs to be monitored.

Dmitry Sazonov
  • 8,801
  • 1
  • 35
  • 61
  • I proposed this method in my question. I was looking for something different, I don't want millions of event filters. – 0xbaadf00d Oct 21 '13 at 07:23
0

I'm lazy so this is what I did (cannot paste code since it's not on this machine).

Added a boolean to my widget base class, "listenToFocusChangesFromChildren"

Then I changed my base class focusInEvent to loop through all parents, and call "childGotFocus" on any that have that boolean set to true.

Lazy but seems to be very effective.

0xbaadf00d
  • 2,535
  • 2
  • 24
  • 46