设置Qt::WindowStaysOnTopHint
this->setWindowFlags(Qt::Tool| Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint|Qt::X11BypassWindowManagerHint);
Qt::WindowStaysOnTopHint帮助文档
Informs the window system that the window should stay on top of all other windows. Note that on some window managers on X11 you also have to pass Qt::X11BypassWindowManagerHint for this flag to work correctly.
windows下
如果不是第一时间启动,还需在类构造函数设置
#ifdef Q_OS_WIN32
::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
#endif
唤醒
#ifdef Q_OS_WIN32
::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
#endif
this->show();
this->setWindowState(this->windowState() & ~Qt::WindowMinimized);
this->raise();
this->activateWindow();