Qt World Summit: Submit your Presentation

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.

  • 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
    if((key == RIGHT || key == ENTER) && currentItem()->type == 2)
    return true;
    return false;

    The menu item is supposed to react to this call via focusInEvent(...) e.g.
    void PlayersControl::focusInEvent ( QFocusEvent * event )

    But sometimes focusInEvent() does not get called.

Log in to reply