OK, finally got the code working correctly.
In terms of focus, the key piece of missing functionality that I added is checking for a focus item in QGraphicsScene event handlers. Specifically, if the graphics scene has a focus item, the code ignores the event and instead calls the default QGraphicsScene event handler. The mouse move event excerpt is below.
if(!focusItem()) { //only handle events if no proxy items are in focus
//rotate openGL scene, etc
}
else {
QGraphicsScene::mouseMoveEvent(event
);
//call this so that proxy widget will receive event }
}
void MyGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
if(!focusItem()) { //only handle events if no proxy items are in focus
//rotate openGL scene, etc
}
else {
QGraphicsScene::mouseMoveEvent(event); //call this so that proxy widget will receive event
}
}
To copy to clipboard, switch view to plain text mode
Before (when the code did not check for a focus item) the openGL scene would rotate correctly when no popup was displayed. However, when the popup was displayed and the user tried to move it, the openGL scene would rotate rather than correctly transferring focus to the popup and moving that instead.
Then, even after I fixed the above problem I ran into an additional issue: calling QDialog::show() and QGraphicsProxyWidget::setFocus() messed up the openGL state. The result was that the QGraphicsScene::drawBackround() code produced artifacts/garbage once the proxy popup was opened.
To fix that problem I added beginNativePainting() and endNativePainting() calls to the drawBackground() definition (which I should have had in place before anyways).
void MyGraphicsScene
::drawBackground(QPainter *painter,
const QRectF &) {
painter->beginNativePainting();
...
painter->endNativePainting();
}
void MyGraphicsScene::drawBackground(QPainter *painter, const QRectF &)
{
painter->beginNativePainting();
...
painter->endNativePainting();
}
To copy to clipboard, switch view to plain text mode
Bookmarks