PopupApplet and setFocus() behaviour

Dmitry Suzdalev dimsuzkde at gmail.com
Thu Aug 13 10:10:57 CEST 2009


Hi guys and girls!

While making some progress on klipper engine+applet I discovered some oddities 
with focus behavior. I hope you can give me some hints about my situation 
(don't get scared by amount of text below, i tried to make it simple to 
follow).

General layout of applet widgets is the following:

Applet is a PopupApplet.
It has a QGraphicsProxyWidget as graphicsWidget(),
which has embedded QWidget (named KlipperWidget)
which has a QListView inside (it displays clipboard history entries).

What I'm trying to do is to make sure that this QListView will always have 
keyboard focus when popup is shown.

I'm doing it by overriding a PopupApplet::popupEvent() and calling 
KlipperWidget's setFocus() function.
KlipperWidget has a QListView set as a focus proxy for this to work.

And it works... but only when I launch applet in 
"plasmoidviewer -f horizontal klipper".

Problem: When applet is inside plasma-desktop, no focus gets set.

I tried to debug this and found that when running as a part of plasma-desktop, 
QListView actually gets only FocusOut event, and not a single FocusIn.

After looking through souces of a popup applet and debugging a bit, i also 
found that probably the following happens when running in plasma-desktop:

1. PopupApplet::popupEvent() arrives before popup gets WindowActivated event
2. I call setFocus()
3. Immediately after this eventloop delivers WindowActivated event ( for 
"dialog" widget inside popupapplet.cpp)
4. WindowActivated event gets inside a QGraphicsScene, after this scene sends 
FocusOut event to any active focus item inside it
5. FocusIn is sent to popupapplet's toplevel dialog, but my widget gets only 
FocusOut

Somehow this doesn't happen for plasmoidviewer. Maybe order of 
Activation/FocusIn event differs there, dunno.

Anyway, if someone has read until here, let me and with a question:

What to do? :-)

It might be a bug somewhere, it might be not. I'm not sure.
I can't find a mechanism to defer my setFocus() until i know that popup dialog 
has been shown. I don't want to use a timer as that's not 100% fix and can 
lead to users noticing a slight delay.

In the end I want to simply ensure that my widget will always have focus when 
shown in a popup. Is this possible? Is there some potential workaround you 
see?

Thanks in advance,
Dmitry.

PS. If you want to look at the code it can be found here:
http://websvn.kde.org/trunk/playground/base/klipper-ng/plasmoid/applet/


More information about the Plasma-devel mailing list