PDA

View Full Version : Deleting characters in QLineEdit widget



Santiago
10th November 2011, 20:54
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:



void BackspaceKeyNotification()
{
if(qlineedit1->hasFocus())
{
qlineedit1->backspace();
}
else if(qlineedit2->hasFocus())
{
qlineedit2->backspace();
}
}


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

Thanks in advance!

Lykurg
10th November 2011, 21:42
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.

Santiago
11th November 2011, 14:18
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!