How can I capture QKeySequence from QKeyEvent depending on current keyboard layout?

后端 未结 7 1454
一向
一向 2020-12-09 12:05

I need to do this for configuring my application. I have QLineEdit field with reimplemented keyPressEvent method.

QKeyEvent *ke = ...
QString txt;

if(ke->         


        
相关标签:
7条回答
  • 2020-12-09 12:49

    Trying to capture a QKeySequence in keyPressEvent might not work as expect. And I found a solution:

    //  || event->type()== QEvent::ShortcutOverride is the key point
    if (event->type() == QEvent::KeyPress || event->type()== QEvent::ShortcutOverride)
    {
        QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
        if (keyEvent->matches(QKeySequence::Save))
        {
            // Do save
        }
    }
    

    I hope that helps someone. : )

    Reference: QWidget::eventFilter() not catching key combinations

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