Qt6 topics merged with General

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";
            qDebug() << "KeyPressEvent";

    In the MainWindow constructor:

    hkWidget = new HotKeyWidget();
    QObject::connect(hkWidget, SIGNAL(minimizeMainWin()), this, SLOT(showMinimized()));
    1. Run the application and bring MainWindow and Widget to front. Click on the Widget to set Focus
    2. Press any key to see KeyPressEvent Debug Message. (Works as expected)
    3. Press Down Key to minimize MainWindow.
    4. Press any key to see KeyPressEvent Debug Message. (Works as expected with MainWindow minimized)
    5. Show MainWindow normal (unminimize) and click Widget again to set focus.
    6. Press Left Key to set Qt:Popup WindowFlag to the widget.
    7. Press any key to see KeyPressEvent Debug Message. (Works as expected with Qt:Popup flag set to the widget)
    8. Press Down Key to minimize MainWindow again.
    9. 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?

  • Lifetime Qt Champion


    Why are you not calling the base class implementation of keyPressEvent ?

Log in to reply