我需要以编程方式知道什么窗口/对话框/小部件是打开的,因为我使用FileOpenEvent
来加载文件,如果我的QMainWindow
是唯一打开的,我只想加载文件。
我发现遍历所有QWindow
s并检查isExposed() == true
多个处理我正在做的一切,除了本机Mac对话框(另存为,打印和打开文件)。因此,这似乎足以满足我的需求:
bool found_exposed_window = false;
foreach (QWindow *window, qApp->allWindows()) {
if (window->isExposed()) {
if (found_exposed_window) {
// This is the second exposed window, meaning the user has something
// open in addition to the main form.
// So, don't try to load a file.
return;
}
found_exposed_window = true;
}
}