Frage

This has happened for every QDialog I pop that fires from either a mouseReleaseEvent on a QGraphicsItem or from a QContextMenu. I don't see what the issue is - the code is pretty simple..

...
void MyQGfxItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    if(event->button() == Qt::RightButton)
    {
        MyDialog someDlg;
        if(someDlg.exec())
        {

        }
    }
}
...

As soon as the dialog is closed, either through OK or Cancel, an empty context menu appears where the event was triggered:

enter image description here

The blank item seems to control if my QDockWidget is hidden or visible.. Any idea what is going on? Numerous Google searches has left me stuck.

Edit - it looks like this only occurs if the Right mouse button is used..

War es hilfreich?

Lösung 2

Ha! Got it. It looks like the QMainWindow grabs Right-click events after everything is finished. Calling this->setContextMenuPolicy(Qt::NoContextMenu) in the QMainWindow suppressed it.

Andere Tipps

According to the docs for QEvent, you should accept() events you do not want propagated to the parent widget. So somewhere in your mouseReleaseEvent, you should just add

event->setAccepted(true);

or

event->accept();

Note that you might also need to put this code in your mousePressEvent, too.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top