Qt 4.5 Focus does not work on QLineEdit

I have a problem with QLineEdit. Even if I set the tab order to start editing this line, after loading the screen, LIne Edit will not automatically receive focus.

I also tried these two lines:

this->activateWindow(); this->lineEdit_password->setFocus(); 

But it still does not work. So maybe someone experienced the same problem ...

Thanks in advance for your help, Boris

+4
source share
2 answers

Another solution is to use a singleShot timer:

 QTimer::singleShot(0,lineEdit,SLOT(setFocus())); 

Then the focus will be set after the application is free. Boris

+8
source

Thank you very much, Krishna, by overriding showEvent () from qwidget:

 void OScreenLogin::showEvent(QShowEvent* e){ this->activateWindow(); this->lineEdit_password->setFocus(); QWidget::showEvent(e); } 

The Edit line gets focus, I believe the other widget had focus set after these two lines. Thanks again, Boris

+2
source

Source: https://habr.com/ru/post/1285936/


All Articles