PDA

View Full Version : How to connect QLineEdit to "ENTER" key press form keyboard.



Channareddy
16th June 2011, 08:57
Hi,
I have two QLineEdits (used to enter Username and Password) & a login button .After entering the text into QLineEdits if user presses ENTER key from keyboard then i want next page to be displayed.Now its happening but i need to use TAB every time after entering the text.I went through Qt doc for "key press events" but i not getting it.
Please explain me with code so that i can understand.

Thank you...:)

Santosh Reddy
16th June 2011, 09:09
Connect QLineEdit::returnPressed() signal to QPushButton::clicked() signal

Channareddy
16th June 2011, 11:25
Ya i got it. I wrote as below

connect(ui->userNameLine, SIGNAL(returnPressed()),ui->homeLoginButton,SIGNAL(clicked()));
connect(ui->userPasswordLine, SIGNAL(returnPressed()),ui->homeLoginButton,SIGNAL(clicked()));

But if i write only in 1st LineEdit and press ENTER its not working.What modifications i have to do for ENTER key to work both 1st & 2nd edit Lines.

Santosh Reddy
16th June 2011, 14:10
But if i write only in 1st LineEdit and press ENTER its not working.What modifications i have to do for ENTER key to work both 1st & 2nd edit Lines.
What do mean by bot working, is the signal not being emittted?

ChrisW67
17th June 2011, 00:58
Santosh Reddy's answer does exactly what you asked for but probably not what you meant. I think this is what you meant:

User types user name then Enter or Tab
Focus moves to password box
User types password
If user presses Enter Login is triggered, or Tab the login button gets focus.


If you want an Enter pressed in the user name box to move focus to the password box (rather than push the login button) then connect returnPressed() to a slot that does that: QWidget::setFocus() for example.

wysota
17th June 2011, 10:43
I suppose you have some kind of button to trigger the login process. Have a look at the QPushButton::default property, I think that's what you're looking for (or maybe not, your description is not clear).