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
Forum Updated to NodeBB v4.3 + New Features

how to handle a delete key press event

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 3.1k 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.
  • M Offline
    M Offline
    ManiRon
    wrote on 12 Aug 2019, 03:53 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 .

    R 1 Reply Last reply 12 Aug 2019, 04:26
    0
    • M ManiRon
      12 Aug 2019, 03:53

      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 .

      R Offline
      R Offline
      Ratzz
      wrote on 12 Aug 2019, 04:26 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.

      M 1 Reply Last reply 12 Aug 2019, 09:04
      1
      • R Ratzz
        12 Aug 2019, 04:26

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

        M Offline
        M Offline
        ManiRon
        wrote on 12 Aug 2019, 09:04 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

        1/3

        12 Aug 2019, 03:53

        • Login

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