PDA

View Full Version : Qt Application Windows Always on Top of External Application Windows



TEAmerc
13th April 2016, 21:14
I have a program in Qt which has a main QMainWindow which creates other QMainWindows that it is the parent of. The problem is all the child QMainWindows are always on top of the parent QMainWindow and any application window from my application is always on top of any other window on the system that isn't part of my application unless the minimize button is pressed on my application.

I just want my application to be like a normal application where whichever window you select is brought to the front, and if a window from another application on the computer is selected then that window goes on top of my application since my application no longer has focus.

I've tried doing a findall in the project and removed all instances of raise(), lower(), and activateWindow() but nothing has changed so far and I doubt this is standard Qt behavior. Is there any other functions that I may be calling that would affect the window ordering? Alternatively is there a signal that QMainWindow has that I may be missing that is emitted when the window gains or loses focus so I can manually bring them to the front when they get focus, and lower the application somehow when none of my application windows have focus?

Thanks

d_stranz
14th April 2016, 17:06
I think your problem is partly due to making the additional QMainWindow instances children of the first QMainWindow. So long as any of those children has focus, it will be on top of the first QMainWindow and all of its siblings. If you want all of your QMainWindows to act independently of each other, you need to create them as full-fledged top-level windows, just like your first QMainWindow. That means creating them parentless (which effectively makes the desktop their parent). You should then be able to raise and lower them individually. You'll have to pay attention to the quitOnLastWindowClosed() slot to make sure you don't end up with a zombie process that continues running even though no windows are visible.

I don't know about the issue of your application windows being on top of other app windows. Could be that fixing the parenting issue might fix that too.

TEAmerc
14th April 2016, 20:43
I changed the child windows to be their own top level windows like you suggested and that fixed my problem of the secondary windows always being on top of the primary window.

Also I found the reason my application was always above any other application was due to a Qt::WindowStaysOnTopHint flag I had set in the primary window while trying to fix this a long time ago and I guess I had forgotten about it when it didn't correct my issue and didn't notice it created the new issue either.

Thanks for the help!