我试图迫使我的应用程序保持在所有的顶部,即使当其他进程弹出的时候。以下是我的main的简化版本
main.cpp
QApplication app{argc, argv};
QQmlApplicationEngine engine;
engine.load(QUrl{"qrc:/file.qml"});
return app.exec();我需要一个Windows和Linux的解决方案。但是,优先考虑的是前者,而且似乎没有Qt解决方案。以下是我尝试过的:
#ifdef _WIN32
HWND hCurWnd = ::GetForegroundWindow();
DWORD dwMyID = ::GetCurrentThreadId();
DWORD dwCurID = ::GetWindowThreadProcessId(hCurWnd, NULL);
::AttachThreadInput(dwCurID, dwMyID, TRUE);
::SetWindowPos(hCurWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
::SetWindowPos(hCurWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
bool ok = ::SetForegroundWindow(hCurWnd);
LOG_INFO() << ok;
::AttachThreadInput(dwCurID, dwMyID, FALSE);
::SetFocus(hCurWnd);
::SetActiveWindow(hCurWnd);
#endifok返回true,但似乎不起作用。启动后,外部进程仍然出现在应用程序的顶部。
加载的QML文件在FullScreen上设置了它的visibility。它的类型是ApplicationWindow。
发布于 2017-03-14 15:11:07
不过,这件事很简单:
setWindowFlags(Qt::WindowStaysOnTopHint) hides Qt Window
因此,我在我的file.qml中写了这个
ApplicationWindow
{
visibility: "FullScreen"
flags: Qt.WindowStaysOnTopHint
}https://stackoverflow.com/questions/42789459
复制相似问题