PDA

View Full Version : Bring window to the front



Barry79
14th August 2009, 10:53
Hi,

How do I ensure that a window displays on top of any other windows on the desktop?

This is how I display a window now -

this->setGeometry(QApplication::desktop()->availableGeometry(1)); this->showFullScreen();

Thanks,

Barry.

burnttoy
14th August 2009, 11:01
QWidget::raise() or QMainWindow::activateWindow.

ActivateWindow is probably what you want but it will have "odd" effects on Windows boxes as if the app window isn't on top you'll get a "flasher" in the task bar instead. That is it won't actually raise the window to the top but show the user that the application requires attention.

The other trick might be to set the "Qt::WindowStaysOnTopHint" attribute on the window. e.g. p_mainWindow->setAttribute(Qt::WindowStaysOnTopHint);

rknowles
14th August 2009, 17:50
I found that this problem is a windows manager problem rather than just Qt. The windows manager handles all windows, but your application can only affect its own windows. My project focuses on X11, where I always found "Qt::WindowStaysOnTopHint" was a hint only, and ignored by the windows manager. I was able to control the windows of my own application to assure that an important one stayed on top of others in the application, but even this was roundabout. I added an eventFilter on all widgets with actions that might cause the windows manager to raise a window to the top. If the event was something like "MouseButtonRelease", I'd queue another event to check on the window layering. When Qt and the windows manager are all done, my new event comes up and I simply "raise" the window I want on top. (If anyone has simpler ideas, I'd love to hear.) Now if you want to keep your application window on top of windows that are not part of your application, I don't know what to do with that!

- Dick