[SOLVED] how to capture the ctrl + c in the eventfilter?



  • i am having problems capturing a Qmenu shortcut in a Qplaintextedit. the problem is when i set the menu item to ctrl + c and click that menu item, nothing happens in the plaintextedit eventfilter. below is the code to try to resolve this issue but nothing happens at all. if i use the short cut of ctrl without the "c" then it works but with the "c" it does not work. help please. thank you in advanced. below is my code.

    @bool MainWindow::eventFilter(QObject *object, QEvent *event)
    {
    if (object == plainTextEdit && event->type() == QEvent::KeyPress)
    {
    QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);

       if (keyEvent->key() == Qt::Key_Control)
        {
            if (keyEvent->key() == Qt::Key_C)
            // do something
            }
        } else
        {
            return QMainWindow::eventFilter(object, event);
        }
    }
    else
    {
        return QMainWindow::eventFilter(object, event);
    }
    

    }@



  • You should try:

    @
    if(keyEvent->key() == Qt::Key_C && keyEvent->modifiers().testFlag(Qt::ControlModifier))
    {
    // eat the ctrl-c which is cmd-c on the mac
    }
    @



  • thank you Volker. it works


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.