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. Dialog apps with Qt::Popup attribute do not get focus when launched via shortcuts
Forum Updated to NodeBB v4.3 + New Features

Dialog apps with Qt::Popup attribute do not get focus when launched via shortcuts

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 596 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.
  • G Offline
    G Offline
    Galicarnax
    wrote on last edited by Galicarnax
    #1

    Here is the minimal example that reproduces weird focus behavior, at least in Ubuntu Linux:

    #include <QtWidgets>
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        QDialog *dialog = new QDialog();
        QHBoxLayout *layout = new QHBoxLayout(dialog);
        QLineEdit *lineedit = new QLineEdit(dialog);
        layout->addWidget(lineedit);
        dialog->setLayout(layout);
        dialog->setWindowFlags(Qt::Popup);
        dialog->setAttribute(Qt::WA_QuitOnClose);
        dialog->show();
        lineedit->setFocus();
        // dialog->raise();
        // dialog->activateWindow();
        return app.exec();
    }
    

    Running the app from terminal gives no surprises. But if I make an OS shortcut that launches the same app, more often than not I end up with the dialog sticking on top of all windows and with blinking cursor waiting there for user's input, but ignoring the input entirely. Instead, the input goes to another app that was previously in focus.

    I use Qt version 5.12. The same happens if I rewrite the code in python using PyQt5. It also does not depend on DE/window manager - I tried this in i3wm, Gnome and xfce - the situation is the same.

    I googled on this, and discovered hints to use raise() and windowActivate(), but found that they make no difference.

    So how do I make a standalone popup menu in Qt that might be called via shortcut without losing focus? I need the popup attribute, since my app needs to behave as a top-level menu (e.g., like dmenu or rofi), i.e. it should appear even above full-screen windows, it should not be tiled in tiling window managers, etc.

    G 1 Reply Last reply
    0
    • G Galicarnax

      Here is the minimal example that reproduces weird focus behavior, at least in Ubuntu Linux:

      #include <QtWidgets>
      #include <QApplication>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          QDialog *dialog = new QDialog();
          QHBoxLayout *layout = new QHBoxLayout(dialog);
          QLineEdit *lineedit = new QLineEdit(dialog);
          layout->addWidget(lineedit);
          dialog->setLayout(layout);
          dialog->setWindowFlags(Qt::Popup);
          dialog->setAttribute(Qt::WA_QuitOnClose);
          dialog->show();
          lineedit->setFocus();
          // dialog->raise();
          // dialog->activateWindow();
          return app.exec();
      }
      

      Running the app from terminal gives no surprises. But if I make an OS shortcut that launches the same app, more often than not I end up with the dialog sticking on top of all windows and with blinking cursor waiting there for user's input, but ignoring the input entirely. Instead, the input goes to another app that was previously in focus.

      I use Qt version 5.12. The same happens if I rewrite the code in python using PyQt5. It also does not depend on DE/window manager - I tried this in i3wm, Gnome and xfce - the situation is the same.

      I googled on this, and discovered hints to use raise() and windowActivate(), but found that they make no difference.

      So how do I make a standalone popup menu in Qt that might be called via shortcut without losing focus? I need the popup attribute, since my app needs to behave as a top-level menu (e.g., like dmenu or rofi), i.e. it should appear even above full-screen windows, it should not be tiled in tiling window managers, etc.

      G Offline
      G Offline
      Galicarnax
      wrote on last edited by Galicarnax
      #2

      Can anybody at least reproduce the same issue? I've experiened it under X11 on four different hosts (Ubuntu + i3, Ubuntu + xfce4, Ubuntu + Gnome, Arch + i3), so it bothers me the issue is largely unknown. It makes an application consisting of a standalone popup dialog basically unusable under X11. Under Wayland there is no such problem. Apparently, in X11 something happens between the shortcut invocation and actual appearance of the widget that jumbles up the input behavior.

      1 Reply Last reply
      0

      • Login

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