void MainWindow::on_actionAlways_on_Top_triggered(bool checked)
{
Qt::WindowFlags flags = this->windowFlags();
if (checked)
{
this->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
this->show();
}
else
{
this->setWindowFlags(flags ^ (Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint));
this->show();
}
}
Run Code Online (Sandbox Code Playgroud)
上面的解决方案有效,但因为setWindowFlags隐藏了窗口,所以需要重新显示它,当然看起来并不优雅.那么如何在没有"闪烁"副作用的情况下为QMainWindow切换"永远在线"?