tags:

views:

515

answers:

2

Hi,

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

+1  A: 

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

Boris Gougeon
A: 

An other solution is to use a singleShot timer :

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

The focus will then be set once the application is free. Boris.

Boris Gougeon