2009-06-08 107 views
4

我遇到了QLineEdit的问题。即使我将Tab键顺序设置为从该行编辑开始,一旦加载了屏幕,内部编辑将不会自动获得焦点。Qt 4.5 Focus在QLineEdit上不起作用

我也试着与此两条线:

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

但是,这仍然没有效果。 所以也许有人遇到了同样的问题...

预先感谢您的帮助, 鲍里斯

+1

作为初始测试,您可以尝试覆盖窗口的showEvent()。在showEvent()中,调用'this-> lineEdit_password-> setFocus();' – Krsna 2009-06-17 16:19:18

回答

8

的其他解决方案是使用一个singleShot定时器:

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

焦点将然后被设置一旦应用程序是免费的。 鲍里斯。

2

非常感谢奎师那,QWidget的的重写showEvent()将工作:

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

lineEdit获得焦点,我猜想其他小部件在这两行之后设置了焦点。再次 谢谢, 鲍里斯

相关问题