Results 1 to 6 of 6

Thread: How to connect QLineEdit to "ENTER" key press form keyboard.

  1. #1
    Join Date
    Jun 2011
    Posts
    26
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default How to connect QLineEdit to "ENTER" key press form keyboard.

    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...

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to connect QLineEdit to "ENTER" key press form keyboard.

    Connect QLineEdit::returnPressed() signal to QPushButton::clicked() signal

  3. #3
    Join Date
    Jun 2011
    Posts
    26
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to connect QLineEdit to "ENTER" key press form keyboard.

    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.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to connect QLineEdit to "ENTER" key press form keyboard.

    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?

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,670
    Thanks
    13
    Thanked 1,595 Times in 1,523 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect QLineEdit to "ENTER" key press form keyboard.

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to connect QLineEdit to "ENTER" key press form keyboard.

    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 11th January 2009, 06:22
  2. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05
  3. How to catch "ENTER" with keyPress?
    By lumber44 in forum Qt Programming
    Replies: 8
    Last Post: 30th July 2007, 17:21
  4. QTextEdit and "Enter" press
    By krivenok in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2006, 13:10
  5. How to write the "Enter" event
    By Sarma in forum Qt Programming
    Replies: 10
    Last Post: 27th March 2006, 09:17

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.