title: QWidget setFocus does nothing
body: <p>I am implementing a custom context menu that is basically a widget called <code>gripmenu</code> containing several other widgets. If the user left clicks, this menu should appear. To hide or delete it if the user clicks outside of it, I need to somehow check if the user click somewhere else. My plan is to ask all its child widgets for <code>-&gt;hasFocus()</code> and if none hasFocus, I will close the menu. But unfortunately I can't set the focus. Why? My code is:</p>
  
  <pre><code>gripmenu = new GripMenu(this);
  gripmenu-&gt;setFocus();
  </code></pre>
  
  <p>And in the <code>gripmenu</code>'s constructor:</p>
  
  <pre><code>GripMenu::GripMenu(){
    [... set things up]
    ui-&gt;lineEdit-&gt;setFocus(); // or any other widget to focus, 
                              // even this-&gt;setFocus() does not work: see below:
    qDebug() &lt;&lt; ui-&gt;lineEdit-&gt;hasFocus(); // returns false!
  }
  </code></pre>
  
  <p>How is it possible that there is no focus immediately after I just set it?</p>
  
  <p>At the end my goal is to mimic a typical context-menu behaviour (meaning that the menu is closed when clicked somewhere else). So if you have better suggestions on how to tackle it, please hint me that way!</p>
  
  <p>EDIT:</p>
  
  <p>I got it working. The hint of Frank Osterfeld was really useful. Still I had to add a "gripmenu->activate()" in the widget "A" that created(needed) the gripmenu, because without it, the active widget would still be "A" after the mouse got released.</p>