Results 1 to 3 of 3

Thread: Maintain QLineEdit Focus

  1. #1
    Join Date
    Apr 2014
    Posts
    7
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Maintain QLineEdit Focus

    Good Day, I am having trouble maintaining the position of the cursor on a simple login application.

    A user selects to login using my interface, this opens up a QDialog window which contains two QLineEdits (username and password), and two QPushButtons (OK and cancel). The very first time this window is displayed, the cursor is present on the username line. However after logging in (either successfully or unsuccessfully) and closing the login window, upon returning to the login window the cursor will now be in position on the password line. I have verified that the cursor position upon re-entering the login window will simply be the last position that the cursor was in upon leaving the login window.

    I need for the cursor to be on the username line every time this window is opened and I am having trouble getting this to occur. I feel that this will be an extremely simple thing to do, but the QT documentation on the web is not proving very useful for this.

    Any help would be greatly appreciated :-)

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,546
    Thanks
    13
    Thanked 1,578 Times in 1,507 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Maintain QLineEdit Focus

    Call QWidget::setFocus() on the user name widget. You could reimplement the dialog showEvent() and call the function there after calling the base implementation.

    Alternatively, in the slots that handle the two buttons set the focus before hiding the dialog.

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

    Chris2oph (12th July 2016)

  4. #3
    Join Date
    Apr 2014
    Posts
    7
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Maintain QLineEdit Focus

    Many thanks for your suggestion, this has worked very nicely! :-)

Similar Threads

  1. QLineEdit focus problem
    By matteo.cozzaglio in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2009, 14:13
  2. QLineEdit Focus
    By zgulser in forum Qt Programming
    Replies: 3
    Last Post: 10th March 2009, 14:04
  3. QLineEdit and focus
    By serega in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2008, 00:49
  4. QLineEdit Focus
    By sulagnp in forum Qt Programming
    Replies: 1
    Last Post: 15th January 2008, 11:25
  5. How can i ask if a qlineedit get focus..
    By otortos in forum Newbie
    Replies: 1
    Last Post: 7th April 2006, 18:23

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.