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

Unable to handle Ctrl+Shift+.

    XMLWordPrintable

Details

    • Linux/Wayland, Linux/X11, Windows

    Description

      Trying to handle it like that:

      #include <QApplication>
      #include <QWidget>
      #include <QLabel>
      #include <QVBoxLayout>
      #include <QtEvents>
      
      class Widget : public QWidget {
      public:
      	Widget()
      	: _layout(this) {
      		_layout.addWidget(&_label);
      	}
      protected:
      	void keyPressEvent(QKeyEvent *e) override {
      		const auto modifiers = e->modifiers()
      			& ~(Qt::KeypadModifier | Qt::GroupSwitchModifier);
      		const auto matches = [&](const QKeySequence &sequence) {
      			const auto events = QKeySequence(modifiers | e->key());
      			return sequence.matches(events) == QKeySequence::ExactMatch;
      		};
      		if (matches(QKeySequence("ctrl+shift+."))) {
      			_label.setText("ctrl+shift+.");
      		}
      	}
      
      	void keyReleaseEvent(QKeyEvent *e) override {
      		_label.setText({});
      	}
      private:
      	QVBoxLayout _layout;
      	QLabel _label;
      };
      
      int main(int argc, char *argv[]) {
      	QApplication app(argc, argv);
      	Widget widget;
      	widget.show();
      	return app.exec();
      }
      

      Doesn't seem to work on Windows with Qt 5.15 (haven't tried later versions) and on Linux (both X11 and Wayland) with Qt 6.5, 6.6, 6.7.

      Although, this seems to work on macOS with Qt 6.2.

      (Personally I have done only testing on Linux, the feedback from Windows and macOS I got from other persons)

      Attachments

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

        Activity

          People

            liaqi Liang Qi
            ilya-fedin Ilya Fedin
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes