Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SetFocus() does not cause a focusInEvent() call

SetFocus() does not cause a focusInEvent() call

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marius63
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi , welcome to qt forums.

      Can you give us some source code to demo this problem?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        marius63
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved