admin管理员组

文章数量:1391733

I tried to override the keyReleaseEvent function, but it causes a loop call due to the automatic repetition when holding down a key, and using isAutoRepeat doesn't work (on Linux X11), as it always returns false.

Reproduce code (Linux X11 only):

#include <QApplication>
#include <QDebug>
#include <QKeyEvent>
#include <QWidget>
class Window : public QWidget {
  public:
    Window(QWidget* parent = nullptr): QWidget(parent) {}
    void keyReleaseEvent(QKeyEvent* event) override {
        if (!event->isAutoRepeat())//Normal on Windows
            qDebug() << "keyRelease";
    }
};
int main(int argc, char** argv) {
    QApplication app(argc,argv);
    Window window;

    window.show();
    return app.exec();
}

Currently, I believe the reason is as mentioned in the documentation:

Note that if the event is a multiple-key compressed event that is partly due to auto-repeat, this function could return either true or false indeterminately.

本文标签: cHow to determine if a key has truly been released in QtStack Overflow