title: How can I prevent a QWidget from painting, but still respond to events?
body: <p>I have a <code>QGLWidget</code> that renders an OpenGL scene inside a Qt application. I would like to add some other translucent Qt widgets that are overlaid on top of the <code>QGLWidget</code>. This is more difficult than with standard widgets since the OpenGL drawing context is unknown to Qt's painter classes. So, if I just do the obvious thing and place a transparent toolbar on top of the <code>QGLWidget</code> for instance, the transparent part of the toolbar instead renders black (it doesn't have access to the OpenGL frame buffer when painting).</p>
  
  <p>It seems that the recommended way for handling this sort of thing is to <a href="http://qt-project.org/doc/qt-4.8/opengl-overpainting.html" rel="noreferrer">overpaint the 2D content after drawing the OpenGL scene</a>. The linked example seems very straightforward, as long as you're just drawing simple shapes. Instead, what I would like to do is to defer the painting of some child <code>QWidget</code> objects to be done inside the paint event for the <code>QGLWidget</code>.</p>
  
  <p>So, my problem boils down to this:</p>
  
  <ol>
  <li>Prevent the overlay <code>QWidget</code>s from painting in the normal, 2D context.</li>
  <li>In the paint event handler for the <code>QGLWidget</code>, paint the overlays after painting the 3D scene that makes up the background.</li>
  </ol>
  
  <p>The second item on this list seems to be simple: I can use <code>QWidget::render()</code> inside the <code>QGLWidget</code>'s paint event to draw the desired widgets on top of the viewport. This works just fine.</p>
  
  <p>The first item is more tricky: I need a way to prevent the widgets from painting during the normal course of events and only paint them in the <code>QGLWidget</code>'s paint handler. One obvious way to do this is to hide the overlays using <code>QWidget::hide()</code>. This does allow me to paint the widgets atop the OpenGL scene as I would like. However, since the widgets are hidden, they do not respond to mouse or keyboard events. As an example, I'm using a <code>QToolBar</code> with a few buttons on it, and the toolbar is painted properly, but is non-functional (none of the buttons respond to clicks). So, if going down this path, it seems that I would need a way to force the widget to still respond to events even though it is hidden.</p>
  
  <p>Another approach that I've tried is to intercept the <code>QToolBar</code>'s paint event using an event filter, with the goal of preventing the toolbar from painting itself. However, the toolbar is still rendered; I'm assuming that this is because the various buttons on the toolbar are child widgets that are still painted, even if I intercept the parent's paint event.</p>
  
  <p>Any ideas on a way that I could accomplish my goal?</p>