2012-10-15 74 views
0

我試圖做simly功能。 當我點擊托盤圖標:Qt應用程序,焦點和顯示/隱藏功能

-A- if app is hide > show 
-B- if app is show and is NOT focus > focus it 
-C- if app is show and focus > hide 

非常笑着,但如果你有重點應用程序,你點擊圖標的嘗試,重點是輸了,現在任務欄被聚焦。所以B條件是真實的,而不是C. 那麼,那是什麼?

回答

0

當主窗口的焦點輸出事件發生後,托盤圖標上的單擊事件發生時,您可以採用C.所以,你可以做這樣的事情:

MainWindow::focusOutEvent(...) { 
    trayIcon->setJustFocussedOut(true); 
    this->someQTimer->start(); 
} 

MainWindow::focusOutDone() { 
    trayIcon->setJustFocussedOut(false); 
} 

MainWindow::someQTimer是QTimer設置爲singleshot模式,並在很短的時間間隔(例如50毫秒)。 setJustFocussedOut方法在托盤圖標中設置一個標誌,使其處理點擊情況C.