SetFocus() does not cause a focusInEvent() call
-
I am using focusInEvent() to capture manually inserted setFocus() calls.
I use this scheme to implement activation without having to subclass.
Fault: sometimes focusInEvent() does not get called.
Inserting a breakpoint (Visual Studio 2010 Ultimate) seems to fix this.
That is, if I run in debug mode with a breakpoint set at some point, the fault does not manifest it self anymore.
The workaround is of course to abandon this scheme and instead subclass and implement activation() or similar.
But I would like to understand the fault.
Thanks. -
Hi , welcome to qt forums.
Can you give us some source code to demo this problem?
-
There's a class MainMenu which processes keyboard events, calling setFocus() of certain menu items.
@
bool MainMenu::eventFilter(QObject *dest, QEvent e)
{
if(e->type() == KEY_PRESSED)
{
int key = ((QKeyEvent)e)->key();
if((key == RIGHT || key == ENTER) && currentItem()->type == 2)
{
currentItem()->setMode(ACTIVE);
currentItem()->controlL60->setFocus();
return true;
}
}
return false;
}
@The menu item is supposed to react to this call via focusInEvent(...) e.g.
@
void PlayersControl::focusInEvent ( QFocusEvent * event )
{
qApp->installEventFilter(this);
changePlayer(currentPlayerIndex);
CALL_METHOD_FOR_EACH_OBJECT(playerWidgets,setFocus());
clearFocus();
}
@But sometimes focusInEvent() does not get called.