PDA

View Full Version : widget focus question



eva2002
11th January 2010, 03:40
I have a gui with multiple LineEdits widget. I am trying to determine which lineedit got focus. I know that there is this hasFocus() method but I can't seems to get it to work.

code:
...
QLineEdit *Name_lineEdit = new QLineEdit();
QLineEdit *Pass_lineEdit = new QLineEdit();

Pass_lineEdit->setFocus();

printf("P focus = %d\n\r", Pass_lineEdit->hasFocus());
printf("N focus = %d\n\r", Name_lineEdit->hasFocus());

app.exec();

Output return
P focus = 0
N focus = 0

Why is Pass_lineEdit->hasFocus() return 0? I would expect it to be 1
Is there any way to determine which widget got focus without having to go through each widget focus property?

wysota
12th January 2010, 00:04
Why is Pass_lineEdit->hasFocus() return 0? I would expect it to be 1
Because Qt is event-driven. You need to return control to the event loop for the focus to change.


Is there any way to determine which widget got focus without having to go through each widget focus property?
QApplication::focusWidget()