Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Widget with Qt::Popup flag ignores KeyPressEvents when MainWindow is minimized
Forum Update on Monday, May 27th 2025

Widget with Qt::Popup flag ignores KeyPressEvents when MainWindow is minimized

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 271 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Ste.
    wrote on last edited by Daniel Ste.
    #1

    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();
    
    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved