这个问题持续了有段时间,我以“PyQt/PySide 设置窗口置顶 setWindowFlags 窗口闪”等关键词在一篇使用C写的代码解决方案中找到了答案
原文链接QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系 - 知乎 (zhihu.com)
void Widget::on_pushButton_clicked()
{
if(!istop)
{
// Qt::WindowFlags m_flags = windowFlags();
// setWindowFlags(m_flags | Qt::WindowStaysOnTopHint);
// show();
qDebug()<<"always top";
QWindow* pWin = this->windowHandle();
pWin->setFlags(Qt::Widget | Qt::WindowStaysOnTopHint);
}else{
//Qt::WindowFlags m_flags = windowFlags();
// setWindowFlags(Qt::Widget);
// //setWindowFlags(NULL);
// show();
QWindow* pWin = this->windowHandle();
pWin->setFlags(Qt::Widget);
qDebug()<<"no always top";
}
istop=!istop;
}
原文中放弃使用setWindow