Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-116221

QShortcut does not work with QWindow

    XMLWordPrintable

Details

    • Windows
    • cd4000a97 (dev)

    Description

      I was happy to see that QShortcut in Qt6 is supposed to work with QWindow.
      Sadly there does not seem to be any reaction at all if I try to attach a shortcut to any of my QWindows.

      I added a code example below.
      The QWidget works, whereas the QWindow doesn't.
      This is what I see with QWidget when I press the "D" key:

      Nothing is logged with QWindow when I press the "D" key.

       

      #include <QApplication>
      #include <QWindow>
      #include <QWidget>
      #include <QShortcut>
      #include <QKeySequence>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QWindow w; // Does not work
          //QWidget w; // Does work
      
          QKeySequence key_sequence = QKeySequence::fromString("D");
          QShortcut* shortcut = new QShortcut(key_sequence, &w);    
      
          QObject::connect(shortcut, &QShortcut::activated, shortcut, [key_sequence]()
          {
              qDebug() << "Shortcut activated: " << key_sequence.toString();
          });
          QObject::connect(shortcut, &QShortcut::activatedAmbiguously, shortcut, [key_sequence]()
          {
              qDebug() << "Shortcut activated ambiguously: " << key_sequence.toString();
          });
      
          w.show();
          return a.exec();
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vestbo Tor Arne Vestbø
            megamouse Patrick Waldner
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes