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

how to handle a delete key press event



  • I have an line edit for which i have set a input mask as ("000.000.000.000") . Now in this line edit when i try to enter the IP address and try to delete it . It deletes the character at the current cursor position and after that it create a space at that location instead of moving the next character to that deleted character position . So How can i make the cursor to move to next position when the delete key is pressed .

    Input Mask :

    ui->lineedit->setInputMask("000.000.000.000");

    Tried codes :

    Event Filter :

     void MainWindow::keyPressEvent(QKeyEvent *event)
     {
        if(event->key() == Qt::Key_Delete)
        { 
         }
     }
    

    Another method Used :

      new QShortcut(QKeySequence(Qt::Key_Delete), this, 
      SLOT(Delete_clicked()));
    

    The above are the two methods tried and found that when the delete key was pressed none of them found to be working as they didnt even come inside the function .



  • @maniron said in how to handle a delete key press event:

    So How can i make the cursor to move to next position when the delete key is pressed .

    Are you looking for https://doc.qt.io/qt-5/qlineedit.html#cursorPosition-prop ?



  • @ratzz Actually i have set input mask for my lineedit . when i press the delete key , it doesnt trigger the delete event


Log in to reply