Unsolved Widget with Qt::Popup flag ignores KeyPressEvents when MainWindow is minimized
-
QtWidgets (5.11) on OS X (Mojave).
The combination of setting Qt::Popup WindowFlag to a Widget and minimizing the MainWindow makes the Widget ignore KeyPressEvents.
To reproduce:
Create a new QtCreator project. Create a custom widget (HotKeyWidget) and reimplement keyPressEvent like this:
void HotKeyWidget::keyPressEvent(QKeyEvent *event) { if(event->key() == Qt::Key_Down) { qDebug() << "Down pressed -> MainWindow minimized"; emit minimizeMainWin(); } else if(event->key() == Qt::Key_Left) { qDebug() << "Left pressed -> Widget WindowFlag Qt::Popup set"; this->setWindowFlag(Qt::Popup); this->showNormal(); } else qDebug() << "KeyPressEvent"; }
In the MainWindow constructor:
this->setWindowTitle("MainWindow"); hkWidget = new HotKeyWidget(); QObject::connect(hkWidget, SIGNAL(minimizeMainWin()), this, SLOT(showMinimized())); hkWidget->setWindowTitle("hkWidget"); hkWidget->showNormal();
- Run the application and bring MainWindow and Widget to front. Click on the Widget to set Focus
- Press any key to see KeyPressEvent Debug Message. (Works as expected)
- Press Down Key to minimize MainWindow.
- Press any key to see KeyPressEvent Debug Message. (Works as expected with MainWindow minimized)
- Show MainWindow normal (unminimize) and click Widget again to set focus.
- Press Left Key to set Qt:Popup WindowFlag to the widget.
- Press any key to see KeyPressEvent Debug Message. (Works as expected with Qt:Popup flag set to the widget)
- Press Down Key to minimize MainWindow again.
- Press any other key and see KeyEvents are being ignored this time.
Did not test in windows yet. I'm not sure if this is expected behavior but to me it looks strange. Is this a bug?
-
Hi,
Why are you not calling the base class implementation of
keyPressEvent
?