How can I simulate user interaction (key press event) in Qt?

前端 未结 2 1514
清酒与你
清酒与你 2020-12-15 17:39

I need to simulate \"Enter\" key event in Qt. How can I do this?

相关标签:
2条回答
  • 2020-12-15 18:30
    QKeyEvent *event = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Enter);
    QCoreApplication::postEvent (receiver, event)
    
    0 讨论(0)
  • 2020-12-15 18:31

    The correct answer might be this:

    QKeyEvent *event = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
    QCoreApplication::postEvent (receiver, event);
    

    in fact there are no matching function for call to

    QtKeyEvent::QtKeyEvent(Type type, int key)

    but there is:

    QtKeyEvent::QtKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers)

    0 讨论(0)
提交回复
热议问题