Bring window to front -> raise(),show(),activateWindow() don't work on Windows
-
In windows, an application can't rais itself in front of the currently active window and it can't pull the focus to itself :-(
What you can do is make it topmost (--> brings it to front) and remove tompost flag afterwards. But it will not get the input focus. -
@
eFlags &= ~Qt::WindowStaysOnTopHint;
@ -
Thank you but there must be something wrong with this code.
The window comes to the front and instantly gets hidden completely. It doesn't even show up in the taskbar anymore.@ Qt::WindowFlags eFlags = this->viewer->windowFlags();
eFlags |= Qt::WindowStaysOnTopHint;
this->viewer->setWindowFlags(eFlags);
this->viewer->show();
eFlags &= ~Qt::WindowStaysOnTopHint;
this->viewer->setWindowFlags(eFlags);@ -
If you will look into assistant you will find there next info
"Note: This function calls setParent() when changing the flags for a window, causing the widget to be hidden. You must call show() to make the widget visible again."So you need to call show() again after second setWindowFlags()
-
Do I need to trigger something else as well?
I tried:
@ SetWindowPos(this->viewer->winId(), HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
SetWindowPos(this->viewer->winId(), HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);@but nothing happened.
-
Hi Hege,
I digged a bit, this is what I did:
@
// HACK: bringing window to top
// from QT documentation:
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// void QWidget::activateWindow ()
// ...
// On Windows, if you are calling this when the application is not currently
// the active one then it will not make it the active window. It will change
// the color of the taskbar entry to indicate that the window has changed in
// some way. This is because Microsoft do not allow an application to
// interrupt what the user is currently doing in another application.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This hack does not give the focus to the app but brings it to front so
// the user sees it.
::SetWindowPos(effectiveWinId(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
::SetWindowPos(effectiveWinId(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
// HACK ENDraise(); show(); activateWindow();
@
This brings the window to front. Is your browser perhaps a topmost window? Or a child of yours?
-
I would kick out the native browser and put everything in a "QWebView":http://doc.qt.nokia.com/4.7/qwebview.html. You have control of the window then.
Is there anything that hinders you from doing it this way (despite having to pack QtWebkit.dll and bloating the package)?
-
I would re-think the design criteria. There is a reason window managers don't allow windows of not-active applications to put themselves at the foreground. Why try to circumvent that? What makes your application so super-extra-special that it would need to go around these intentional limitations?
-
@Volker:
I still work on z/OS and like my applications slim, so having a QtWebkit just for that purpose isn't an option.@Ander:
My application isn't super special but it brings the browser in front of itself as well. It would be ok if it was possible to start the browser behind it (my application is only like 300 x 400 pixels, not resizeable).An option would be to keep it topmost until the user either allows access to Twitter via oAuth v1 or the request times out but I don't really want to play with the topmost-property as that is what I consider a design-fault.
-
Maybe "QTextBrowser":http://doc.qt.nokia.com/4.7/qtextbrowser.html fits your needs already. It does not need webkit and is included in QtGui module, that you need anyways.