Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

map one key to another (e.g. Return to Enter)



  • Hello,

    is it in general possible to globally map the return key to the enter key for the whole application, or at least some widget.
    I have a itemview with some custom delegates and I can finish the editing by pressing the enter key, however the return key does not work.

    EDIT:

    I'm kind of confused, when I try to catch the event and then forward it i can catch for example the Qt::Key_Escape but not the Qt::Key_Return. Where is the differnce??

    bool MainWindow::eventFilter(QObject *target, QEvent *event)
    {
        // shortcut keys
        if(event->type() == QEvent::KeyPress)
        {
            QKeyEvent * keyEvent = dynamic_cast<QKeyEvent*>(event);
            if(keyEvent->key() == Qt::Key_Escape)
            {
                std::cout << "Escape" << std::endl;
            }
            if(keyEvent->key() == Qt::Key_Enter)
            {
                std::cout << "Enter" << std::endl;
            }
        }
        return false;
    

    }

    EDIT: I guess the problem is, that the Qt::Key_Enter event is processed by some button in the GUI that gets clicked when the Enter key is pressed. I have disabled the focus for the button, but it does not help.


Log in to reply