Bring window to front -> raise(),show(),activateWindow() don’t work

◇◆丶佛笑我妖孽 提交于 2019-11-27 22:47:59
Johan Råde

This problem is specific to Windows. If the active window belongs to some process, then Windows does not allow other processes to change the active Window.

(Do not try the following: https://wiki.qt.io/Qt_project_org_faq#QWidget_::activateWindow.28.29_-_behavior_under_windows)

try this:

viewer.setWindowState( (windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
viewer.raise();  // for MacOS
viewer.activateWindow(); // for Windows

it work in my project ( in my project viewer is QMainWindow): https://github.com/iptton/Rythem .

for ( QWindow* appWindow : qApplication.allWindows() )
{
  appWindow->show(); //bring window to top on OSX
  appWindow->raise(); //bring window from minimized state on OSX

  appWindow->requestActivate(); //bring window to front/unminimize on windows
}

Note that this also brings up the window from other virtual desktops on both OSX and Windows. I did not test this on linux, it may work though.

This issue is not specific to Windows....I have the same issue on Linux. My solution was to close() the window before I re open() it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!