PDA

View Full Version : How to check if QWidget is overlapped by other windows



arturo182
17th September 2010, 15:07
The title pretty much says it all.
I have a QMainWindow which visibility I want to toggle when clicking the tray icon. I'm using this code:

if(!getMainWnd()->isVisible()) {
getMainWnd()->show();
getMainWnd()->raise();
getMainWnd()->activateWindow();
} else {
getMainWnd()->hide();
}

It works pretty well but there's one problem, when my main window is overlapped by other windows and programs, it's still considered visible, so when I click tray icon, it get hidden.

I want to modify my code to do this:
1. If window is hidden, show it.
2. If window is visible (and on top), hide it.
3. If window is visible but under other windows, raise it.

Can this be achieved with Qt, or do I have to use WinApi, cause I would really want my code to stay multi-platform.

PS. Using isWindowActive, doesn't work, cause when I click tray icon, the window looses focus, so isWindowActive always returns false.

arturo182
19th September 2010, 10:54
Sorry for double posting, but - anybody?