First, a user-level description of my problem:

I wrote a popup window that hovers when a user right-clicks on a triangle mesh. The popup window appears correctly. However, the popup does not handle click and move events correctly, and instead they are passed through to the open gl window. (For example, attempting to move the popup rotates the scene.)

Now the code:

I wrote a QGraphicsView and attached a custom QGraphicsScene to it. The custom QGraphicsScene overrides keyboard and mouse callbacks.

To implement my right-click popup window, I created a minimal custom proxy class. It looks like this:

Qt Code:
  1. class ProxyWidget : public QGraphicsProxyWidget {
  2. public:
  3. ProxyWidget(QGraphicsItem *parent = 0, Qt::WindowFlags flags = 0) : QGraphicsProxyWidget(parent, flags) {
  4. setFocusPolicy(Qt::StrongFocus);
  5. }
  6. };
To copy to clipboard, switch view to plain text mode 

My popup widget class is named "SelectionPopup." To initialize the proxy class, I do this:

Qt Code:
  1. void SelectionPopup::initProxy() {
  2. m_proxy = new ProxyWidget(NULL, Qt::Tool);
  3. m_proxy->setWidget(this);
  4. MainWindow::ptrGraphcsView()->scene()->addItem(m_proxy);
  5.  
  6. MainWindow::ptrGraphcsView()->scene()->setActiveWindow(m_proxy);
  7. m_proxy->setFocus();
  8. }
To copy to clipboard, switch view to plain text mode 

Then in my overridden setVisible method, I set the proxy widget's focus like so:

Qt Code:
  1. void SelectionPopup::setVisible(bool visible) {
  2. if (visible) {
  3. MainWindow::ptrGraphcsView()->scene()->setActiveWindow(m_proxy);
  4. m_proxy->setFocus();
  5. }
  6. else {
  7. MainWindow::ptrGraphcsView()->scene()->setActiveWindow(0);
  8. }
  9. }
To copy to clipboard, switch view to plain text mode 

So, as I said above, after the setVisible call, the popup appears beautifully, but I am unable to click on or move it. The mouse events are passed straight to the QGraphicsScene event handlers.

Does someone know what is going on? With a debugger I can see that within the QGraphicsScene, "focusItem()" returns the proxy widget. However the program behaves as if the opengl widget still has focus.

How can I change the code so that the proxy window behaves correctly when in focus, and (also when the proxy widget is in focus) QGraphicsScene ignores mouse input? Do I need to implement event handling with a custom QGlWidget? Do I need to set some additional flags in my QGraphicsScene class?

Any help is appreciated and I will gladly provide more information if needed. Thanks.