Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt 4.5 Focus doesn't work on QLineEdit

Tags:

focus

qt4

I got an issue with a QLineEdit. Even if I set the tab order to start at this line edit, once the screen is loaded the LIne Edit won't get the focus automatically.

I've also tried with this two lines :

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

But this has still no effect. So maybe someone experienced the same issue...

Thanks in advance for your help, Boris

like image 904
Boris Gougeon Avatar asked Dec 29 '22 22:12

Boris Gougeon


1 Answers

Thank you very much Krsna, overriding the showEvent() of the qwidget will work :

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

The lineEdit gets the focus, I guess that an other widget had the focus set after these two lines. Thanks again, Boris

like image 190
Boris Gougeon Avatar answered Jan 28 '23 06:01

Boris Gougeon