ActivateWindow() does not send window to front
-
I use qtsingleapplication solution to ensure that only one instance of the application is running.
When the second instance is started then it sends message to the already running process.
Already running process should bring it's window to front. How to achieve this?
I used activateWindow() and raise() but it is not a solution (and not a Qt bug - this is the limitation described in the documentation). These calls just "highlight" window in task bar.
I found solution for Windows.
I cannot find solution for Linux. I am interesting in GNOME on Suse Linux (SLED 10).
Does anybody solved this issue?
-
Here is how I do it:
@showNormal();
raise();
activateWindow();@and my window has Qt::Popup flag set.
-
Thank you, I will try this sequence.
I think that in most cases it works. I will try to describe the case when it doesn't work.
-
I use this sequence in my timer and I had no problems with it. Every time the timer fired, the timer window popped up as needed. But if you find the use case when it doesn't work, I will investigate it.
-
if your main window is in the background and you want to activate it with a qsingleapp, you will have problems bringing the window to the front.
An application can't pull the focus on windows. and activate and rais will bring it to front in some cases but not in all :-( That's why we have this HACK:@ // THIS IS A HACK:
// 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(); pWidget->show(); // pWidget->setFocus(); this does not work :-( pWidget->activateWindow(); pWidget->raise();
@
It always brings the window to the front, but the focus is somewhere in the system :-( In some other app...
-
[quote author="Gerolf Reinwardt" date="1290760605"]That's why we have this HACK[/quote]
Thank you for code.
Sorry, but what OS is the target of this hack? I have solved the problem on Windows with the similar code. I need solution for Linux.
-
That is only for windows, but handles also cases, where rais does sometime not work.
I think, for linux, you have to do something like the win 32 call to SetWindowPos(Toplevel) with X11 calls. I didn't find a solution that works without platform specific code. If you look at the code of QWidget setting topmost, you could find how it works on linux and try that out... -
[quote author="Gerolf Reinwardt" date="1290761338"]If you look at the code of QWidget setting topmost, you could find how it works on linux and try that out...[/quote]
Thanks. Already done without any success :)
-
[quote author="lyuts" date="1290759622"]Here is how I do it:
@showNormal();
raise();
activateWindow();@and my window has Qt::Popup flag set.[/quote]
Thank you for advice. I cannot reproduce bug with this code. Now I am going to handle the application to our QA team and to wait for results :)
-
@blex
In linux i use this:if(!this->isActiveWindow()){
this->setWindowFlags((windowFlags() & Qt::WindowStaysOnTopHint));
this->setWindowFlags((windowFlags() & ~Qt::WindowStaysOnTopHint));
this->show();} -
I use this in windows, it works
Qt::WindowFlags flags = windowFlags(); this->setWindowFlags((flags | Qt::WindowStaysOnTopHint)); this->showMaximized(); this->setWindowFlags(flags); this->showMaximized();