PDA

View Full Version : QLineEdit lost focus



codebehind
3rd May 2007, 20:02
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.

marcel
3rd May 2007, 20:19
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

codebehind
3rd May 2007, 20:39
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?

codebehind
3rd May 2007, 21:51
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?

codebehind
3rd May 2007, 22:40
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.

TheRonin
4th May 2007, 16:02
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. :D

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