Results 1 to 2 of 2

Thread: Clear focus on editingFinished

  1. #1
    Join Date
    Mar 2011
    Posts
    25
    Thanks
    7
    Qt products
    Qt4

    Default Clear focus on editingFinished

    I thought that when pressing the enter key on a QLineEdit, it would remove the focus (and the cursor wouldn't be visible anymore).
    For some reason it doesn't behave that way in this simple example. Can somebody explain why?

    Qt Code:
    1. LineEditTest::LineEditTest(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. QLineEdit *edit = new QLineEdit;
    5. Q_ASSERT(connect(edit, SIGNAL(editingFinished()), this, SLOT(SlotTextEdited())));
    6.  
    7. l->addWidget(edit);
    8. setLayout(l);
    9. }
    10.  
    11.  
    12. void LineEditTest::SlotTextEdited()
    13. {
    14. QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(sender());
    15. double value = lineEdit->text().toDouble();
    16. ...
    17. // lineEdit->clearFocus(); // If this line is enabled the cursor disappears
    18. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Clear focus on editingFinished

    Return/Enter doesn't influence focus unless it is programmed to do so. Tab is the key for changing focus. By the way, using editingFinished() is probably not the proper way of doing what you want. "returnPressed()" would be a much better choice to react on the return key by losing focus. Of course editingFinished() is a good place to react on changes to the text of the edit.
    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.


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

    iwatsu (10th October 2011)

Similar Threads

  1. QComboBox editingFinished
    By aekilic in forum Qt Programming
    Replies: 6
    Last Post: 28th November 2020, 09:17
  2. Need a signal almost like editingFinished
    By eric.frederich in forum Qt Programming
    Replies: 4
    Last Post: 25th February 2011, 18:46
  3. editingFinished of QLineEdit
    By weixj2003ld in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2009, 10:06
  4. QDialog, editingFinished, and Cancel Button.
    By jeffpogo in forum Qt Programming
    Replies: 8
    Last Post: 3rd June 2009, 04:22
  5. editingFinished() signal
    By jamadagni in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 06:39

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.