问题:
一个屏幕screen下,进行多个窗体form(ui)切换,会发现失去焦点、聚焦,
尝试:
1.不进行界面切换,则Qt运行时,窗体form(ui)聚焦正常,
2.不使用EventFilter()函数,多个窗体form(ui)切换,Qt运行时,焦点、聚焦正常,
3.在eventFilter()函数中,在一个窗体form(ui),写入聚焦代码(如下),其结果为,
lineEdit只有编辑模式setEditMode(),没有光标setEnabled(),
此时,没有form(ui)焦点,需要按下Tab键才出现聚焦,尝试无效!
//事件过滤器
bool form1::eventFilter(QObject *watched,QEvent *event)
{
if( !this->lineEdit ->hasFocus() && !this->lineEdit_2->hasFocus() && !this->lineEdit_3->hasFocus() &&
!this->lineEdit_4->hasFocus() && !this->lineEdit_5->hasFocus() && !this->lineEdit_6->hasFocus() &&
!this->lineEdit_7->hasFocus() && !this->lineEdit_8->hasFocus())
{
//this->lineEdit->setFocus();
this->lineEdit->setEditMode(true);
this->lineEdit->setEnabled(true);
//return true;
}
//交由QWidget的事件过滤器
return QWidget::eventFilter(watched,event);
}
4.在多个窗体的EventFilter()函数中,写入上述代码,聚焦冲突报警,尝试无效!
原因:
在EventFilter()函数中,一个screen只有一个聚焦点,
界面切换时,聚焦点没有切换过来,所以form(ui)按下Tab键出现聚焦点,
两个form(ui)界面同时聚焦时,自然会报错,
解决方案:
1.所有的控件(如lineEdit等)全部在一个窗体form(ui)中实现,
2.对每一个窗体form(ui)生成一个屏幕screen。