Results 1 to 3 of 3

Thread: Deleting characters in QLineEdit widget

  1. #1
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Deleting characters in QLineEdit widget

    Hi All,

    I have two QlineEdit widgets in my application and I want delete the characters when I press the Backspace key (I´m using a Windows Standard mobile device). When I enter characters and press Backspace, they are deleted one by one, as expected. The problem is when a move to the other QLineEdit which has already characters entered, when I press Backspace key all the characters are deleted, instead of one by one. One workaround is entering any character and then Backspace key will work correctly. Additionally, in this case, when I press Left/Right arrow key, the cursor does not move, it remains in the last character at the right.

    Here is the code that I use to delete characters:

    Qt Code:
    1. void BackspaceKeyNotification()
    2. {
    3. if(qlineedit1->hasFocus())
    4. {
    5. qlineedit1->backspace();
    6. }
    7. else if(qlineedit2->hasFocus())
    8. {
    9. qlineedit2->backspace();
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Can someone tell me why the backspace() function deletes all characters when I move to another QLineEdit?

    Thanks in advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Deleting characters in QLineEdit widget

    Hi,

    this is most probably because on a change you select all text on the line edit. Thus the whole is being deleted when you call QLineEdit::backspase() like the documentation says. So before calling backspace() make sure no text is selected and the cursor is at the end.

  3. The following user says thank you to Lykurg for this useful post:

    Santiago (11th November 2011)

  4. #3
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Deleting characters in QLineEdit widget

    Quote Originally Posted by Lykurg View Post
    Hi,

    this is most probably because on a change you select all text on the line edit. Thus the whole is being deleted when you call QLineEdit::backspase() like the documentation says. So before calling backspace() make sure no text is selected and the cursor is at the end.
    You were right, I did your suggestion and it worked fine.

    Thanks a lot for your help!

Similar Threads

  1. Deleting children of a widget
    By ComServant in forum Newbie
    Replies: 5
    Last Post: 7th October 2011, 00:09
  2. deleting a widget
    By john_god in forum General Programming
    Replies: 1
    Last Post: 30th December 2010, 09:36
  3. Replies: 7
    Last Post: 19th May 2010, 13:24
  4. QLineEdit: how to avoid characters insertion?
    By QAlex in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2010, 11:04
  5. How to adjust spacing between characters in QLineEdit?
    By bzjbest in forum Qt Programming
    Replies: 2
    Last Post: 2nd January 2008, 07:44

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.