Results 1 to 6 of 6

Thread: QLineEdit lost focus

  1. #1
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QLineEdit lost focus

    I have an application with some QLineEdit elements. Their signal lostfocus is conected with the QDialog slot which i defined "SetKoraki()".

    Then i have a button "btnGraf" which opens another window - a widget derivered from a QwtPlot. When the window opened the main dialog lost the focus and it is OK.
    What i don't understand is why the QLineEdit set the signal lostfocus??
    I've tried to workaround whit using the function isModified(), but it looks like the text in the QLineEdit has been changed. but it hasn't?

    the project sourec files are attached.
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit lost focus

    isModified() returns true every time the user changes the text. Only setText can reset it to false.

    Why don't you use editingFinished() instead ( is that available in Qt3? ). If it isn't avalable, then install overwrite keyPressEvent in a custom QLineEdit, and emit a signal when enter or return are pressed.

    Regards

  3. #3
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit lost focus

    isModified() returns true every time the user changes the text. Only setText can reset it to false.
    The problem is that i haven't change it.

    When the window opened the main dialog lost the focus and it is OK.
    What i don't understand is why the QLineEdit set the signal lostfocus??
    If I understand it. When the Dialog lost its focus then every single object on it emits the lostfocus signal?

  4. #4
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit lost focus

    now i'm a little bit more confused.
    I have 4 QlineEdit all with lostfocus signal conected to a slot (for each QLineEdit a diferent slot).
    in each slot i put a line of code that display a text like "i'm in the slot x" - debug of course

    so each time i open a new window the QlineEdit lost its focus... OK
    i left the cursor each time in a diferent QLineEdit (each time the focus was on a different QLineEdit). When I've opened a window the box lost its focus ... OK
    In all described cases i have never changed the text.

    then i add a line of code: if (!box.isModified()) return
    i've put the line before the debug text

    i've repeat all over again. AND the result was... Just in one QLineEdit the flag modified was true. WHY? am i missing something? is there a propertie to define?

  5. #5
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit lost focus

    i found the problem. It was me!!!

    i've looked to the documentation of QLineEdit and found an intresting description.
    The modified flag is reset by the clearModified() or setText()!!!
    in all my code i've never use any of them.
    so i've put in all slots that are conected with QLineEdit boxes a clearModified() and gues... IT WORKS JUST FINE

    sorry, for wasting your time.

  6. #6
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit lost focus

    Quote Originally Posted by codebehind View Post
    i found the problem. It was me!!!
    ....
    sorry, for wasting your time.
    You haven't wasted anyone's time. Someone else might run into the same problem and will be able to learn from this thread.

    Wise men learn from their mistakes...wiser men learn from other people's mistakes.

Similar Threads

  1. QAction shortcuts from QLineEdit
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 4th March 2007, 16:43
  2. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 07:09
  3. Tab/Enter focus problem
    By b1 in forum Qt Programming
    Replies: 4
    Last Post: 24th October 2006, 00:34
  4. Replies: 3
    Last Post: 8th September 2006, 19:54
  5. How can i ask if a qlineedit get focus..
    By otortos in forum Newbie
    Replies: 1
    Last Post: 7th April 2006, 19:23

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.