【发布时间】:2010-08-10 08:22:05
【问题描述】:
大家好,
在我的 QT 应用程序中,我有几个 QMainWindow 实例。 我在 Application Context 对象中跟踪打开的 QWindow 对象;
在某一时刻,当单击菜单项时,我想浏览所有这些 QWindows 并检查哪个窗口处于活动状态并且 执行一些操作。
请参考以下代码sn-p:
//Just a confirmation dialog
QMessageBox msgBox(this->getMainWindow());
msgBox.setText("This will discard existing project");
msgBox.setInformativeText("All Contour data and Volume data will be discarded");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
if(msgBox.exec()==QMessageBox::Cancel)
{
return
}
//This is where I check the active window.
QList<MainWindow*> lst= applicationContext.getOpendedWindows();
for(i=0;i<lst.size();i++)
{
MainWindow *win=lst.value(i);
//Check if this is the active window
if(win.isActive()){ // tried (win==QApplication::activeWindow()) also
//DO SOMETHING with 'win' object
}
}
}
当我在检查前不显示确认对话框时,此检查工作正常。 也就是说,当我注释掉“msgBox.exe()”行时,我可以从列表中找到一个活动窗口。
QMessageBox 的显示是否改变了焦点窗口?
有什么建议吗?
提前致谢,
漫画
【问题讨论】:
-
您确实意识到您已经发布了两次相同的问题? stackoverflow.com/questions/3447179/… 和 stackoverflow.com/questions/3447165/…
-
对不起,我删除了重复的