c++ - How to determine if a key has truly been released in Qt? - Stack Overflow

I tried to override the keyReleaseEvent function, but it causes a loop call due to the automatic repeti

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744771883a4592807.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信