如何在Qt中发布键组合事件,如CTRL-L

时间:2018-02-05 09:53:14

标签: qt qkeyevent qkeysequence

我知道如何发布单键事件

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

现在我想发布关键事件的组合 例如QKeySequence(tr("Ctrl+L"));

这是发布关键序列事件的正确方法吗?

    // First key event - 'Ctrl'
    QKeyEvent *poFirstKeyEvent = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Control, Qt::NoModifier);
    QCoreApplication::postEvent (this, poFirstKeyEvent);

    // Second key event - 'L'    
    QKeyEvent *poSecondtKeyEvent = new QKeyEvent ( QEvent::KeyPress, Qt::Key_L, Qt::NoModifier);
    QCoreApplication::postEvent (this, poSecondtKeyEvent);

实现此目的的其他任何方式?

谢谢,

0 个答案:

没有答案