glafauci
20th November 2012, 14:34
Hi, folks.
I'm in trouble from yesterday for a strange behavior of QLineEdit.
I need to keep trace (and manage) the moment when this widget (QLineEdit) lose its focus. I need three consecutive QlineEdit widgets, and I must control the FocusOut event of every widget.
I followed two lines:
1. install the InstallEventFilter for each widget, and then declare and code the EventFilter method for the window that manage the events
or
2. subclass QLineEdit and, within the QLineEdit::FocusOut event, emit a new signal. This signal is linked through a connection to a slot, in the window where I need to manage the event.
Both lines had the same problem: when one widget loses the focus, two event raises: the first from the next widget (!!), then the correct one. This behavior repeats for every widget.
To better explain, suppose we have three consecutive QLineEdit widget, named Line1, Line2 and Line3. When Line1 loses focus, first raise Line2 event and then Line1 event.
When Line2 loses focus, first raise Line3 event and then Line2 event.
When Line3 loses focus, first raise Line1 event and then Line2 event.
This strange behavior ceases when beneath the three widgets I insert other widgets that don't handle their events.
Why?
I attach to this post one example project that explaines what I say.
To point out this problem, switch the three TextLabel widgets in the main window Designer file (MainWindow.ui) from focusPolicy::NoFocus to focusPolicy::StrongFocus. When the focus policy is set to NoFocus the error raises, but when the focus policy is set to StrongFocus all goes well.
Notice that the same problem raises if I subclass QLineEdit, managing a new signal from FocusOut event.
I'm in trouble from yesterday for a strange behavior of QLineEdit.
I need to keep trace (and manage) the moment when this widget (QLineEdit) lose its focus. I need three consecutive QlineEdit widgets, and I must control the FocusOut event of every widget.
I followed two lines:
1. install the InstallEventFilter for each widget, and then declare and code the EventFilter method for the window that manage the events
or
2. subclass QLineEdit and, within the QLineEdit::FocusOut event, emit a new signal. This signal is linked through a connection to a slot, in the window where I need to manage the event.
Both lines had the same problem: when one widget loses the focus, two event raises: the first from the next widget (!!), then the correct one. This behavior repeats for every widget.
To better explain, suppose we have three consecutive QLineEdit widget, named Line1, Line2 and Line3. When Line1 loses focus, first raise Line2 event and then Line1 event.
When Line2 loses focus, first raise Line3 event and then Line2 event.
When Line3 loses focus, first raise Line1 event and then Line2 event.
This strange behavior ceases when beneath the three widgets I insert other widgets that don't handle their events.
Why?
I attach to this post one example project that explaines what I say.
To point out this problem, switch the three TextLabel widgets in the main window Designer file (MainWindow.ui) from focusPolicy::NoFocus to focusPolicy::StrongFocus. When the focus policy is set to NoFocus the error raises, but when the focus policy is set to StrongFocus all goes well.
Notice that the same problem raises if I subclass QLineEdit, managing a new signal from FocusOut event.