1.函数说明 先看一下官方文档对该函数的说明: void QWidget::setFocus(Qt::FocusReason reason) Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. 因此,当使用该函数时需要满足:当前部件或者其父部件是active window。 2.问题分析 基于此,我用qDebug添加了部分调试代码,如下: void MyWidget::SetInitFocus(