mardi 21 avril 2015

How do QT focusproxies split focus between proxy and widget

Trying to create some custom widget as an aggregation of standard widgets, I came upon few things on focusproxies widget I cannot understand.

from QWidget doc :

void QWidget::setFocusProxy ( QWidget * w )
Sets the widget's focus proxy to widget w. If w is 0, the function resets this widget to have no focus proxy.
Some widgets can "have focus", but create a child widget, such as QLineEdit, to actually handle the focus. In this case, the widget can set the line edit to be its focus proxy.
setFocusProxy() sets the widget which will actually get focus when "this widget" gets it. If there is a focus proxy, setFocus() and hasFocus() operate on the focus proxy.

I am exactly in the situation above, a QLineEdit (plus some stuff without focus) in a custom QWidget.

Some point are still obscure to me : Once the proxy is set and working, no focus event are generated inside the original widget. In short, QWidget::focusOutEvent(QFocusEvent *event) is no longer called.

This sound strange to me, because it means that the widget getting the focus and forwarding it to any child widget lose all processing linked to this event. Doesn't look like a proxy to me but more like a delegate...

Could be I'm wrong and there is a deep meaning in doing that, in this case I'm 'deeply' interested too !

End of the day, I am also looking for an elegant solution to execute something upon a focus out event of a child widget (identical to focus out of my custom widget). I have the possibility to subclass systematically the child, reimplement the focusOutEvent handler and emit a signal inside the function that I will catch inside my custom widget. I find that this is however lacking elegance :(


Aucun commentaire:

Enregistrer un commentaire