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

How to assign TAB to ENTER or RETURN key in TableView?



  • Hi,
    As you know we can move between the cells by TAB key in TableView. But I want to use RETURN or ENTER key.
    I tryed event filter but could not get it.

    bool ProfilKesim::eventFilter(QObject *object, QEvent *event)
    {
        if(event->type() == QEvent::KeyPress){
            QKeyEvent* key = static_cast<QKeyEvent*>(event);
    
            if ( (key->key()==Qt::Key_Enter) || (key->key()==Qt::Key_Return) )
            {
                if(object==ui->tVDetay) /*This mean thet TableView?*/
                {
                         /*I tryed this but no result?*/         
                        /*I need to assign TAB to ENTER key here!!!!*/                      
                    QApplication::postEvent(this, new QKeyEvent(key->type(), Qt::Key_Tab, key->modifiers());
                }else focusNextChild();
            }
    
        }
    
    
        return false;
    }
    

    Regards,
    Mucip:)



  • Hi,
    I found solution here...

    Shortly:

    QKeyEvent * eve1 = new QKeyEvent (QEvent::KeyPress,Qt::Key_A,Qt::NoModifier,"a");
    QKeyEvent * eve2 = new QKeyEvent (QEvent::KeyRelease,Qt::Key_A,Qt::NoModifier,"a");
    
    qApp->postEvent((QObject*)ui->myEdit,(QEvent *)eve1);
    qApp->postEvent((QObject*)ui->myEdit,(QEvent *)eve2);
    

    Regards,
    Mucip:)


Log in to reply