4

我遇到了 QLineEdit 的问题。即使我将选项卡顺序设置为从该行编辑开始,一旦加载屏幕,行编辑也不会自动获得焦点。

我也试过这两行:

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

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

提前感谢您的帮助,鲍里斯

4

2 回答 2

8

另一种解决方案是使用 singleShot 计时器:

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

一旦应用程序空闲,焦点将被设置。鲍里斯。

于 2009-06-17T21:29:05.227 回答
2

非常感谢奎师那,覆盖 qwidget 的 showEvent() 将起作用:

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

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

于 2009-06-17T17:37:01.977 回答