PDA

View Full Version : Focus Out problem



Chirag
29th April 2011, 12:51
I've tried some controls of QT e.g. QLineEdit. I found that they are not giving focus out event even though it should as per standard behavior. Previously I was using wxWidget and in wxWidget has fine controls over focus. In wxWidget if I am clicking out side the text box, text box regularly gives me Kill focus event. But its not here case with Qt.

Can any body tell me if I am doing something wrong?
Basically I want to receive focus lost event whenever I click outside QLineEdit. If its not possible with QLineEdit please let me know if any other control can perform similar...

Thanks,
Chirag.

akiross
30th April 2011, 01:30
Hi,
Qt has a fine control over focus, too.
I think your problem is the focus policy: one widget at time may have the focus, and if one has it, you shall pass the focus to another widget to remove it or clear the focus for that widget. In Qt, QWidget has by default the policy of not accepting focus, while QLineEdit has the policy of accepting it: this is why, if you click on another input field, the original focus is loosed.
If you want to clear the focus from your QLineEdit by just clicking the window, cou can call yourWindow->setPolicy(Qt::StrongFocus).
HIH
~Aki

Chirag
2nd May 2011, 06:32
Thanks a lot akiross! It fixed my problem! But I want to know little bit more if there is any side affect of setting strong focus on main window.