在我的QT應用程序中,我有幾個QMainWindow實例。 我跟蹤應用程序上下文對象中打開的QWindow對象;
在一個點上,當點擊菜單項時,我想通過所有這些QWindows並檢查哪個窗口處於活動狀態,並執行一些操作。
請參考下面的代碼片段:
//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的顯示是否改變焦點窗口?
對此有任何提示?
由於提前,
umanga
你知道你已經發布了兩次相同的問題嗎? http://stackoverflow.com/questions/3447179/how-to-find-active-qmainwindow-instance和http://stackoverflow.com/questions/3447165/how-to-find-active-qmainwindow-instance – 2010-08-10 08:43:40
對不起那我刪除了重複 – 2010-08-10 08:56:10