【QT】新弹窗默认无焦点

1.新窗口界面focusPolicy设置为StrongFocus

2.重写showEvent函数

void ResetPasswordDialog::showEvent(QShowEvent *e)
{
    if(this->focusWidget()){
        this->focusWidget()->clearFocus();
    }
    ui->pushButton_ok->setAttribute(Qt::WA_UnderMouse,false);
    this->setFocus();
    QDialog::showEvent(e);
}

ui->pushButton_ok->setAttribute(Qt::WA_UnderMouse,false);

为设置按钮为非鼠标悬浮状态

猜你喜欢

转载自blog.csdn.net/y7u8t6/article/details/83415229