Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to handle a delete key press event

how to handle a delete key press event

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on last edited by
    #1

    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 .

    RatzzR 1 Reply Last reply
    0
    • ManiRonM ManiRon

      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 .

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @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 ?

      --Alles ist gut.

      ManiRonM 1 Reply Last reply
      1
      • RatzzR Ratzz

        @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 ?

        ManiRonM Offline
        ManiRonM Offline
        ManiRon
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved