QMainWindow windows always on top not working sometimes
-
On windows 7 I have problem with window flag. I added this line in the constructor
setWindowFlags(Qt::WindowStaysOnTopHint );
when windows is going to render (after ctrl + r in qt creator) if suddenly i click on somewhere on text editor(qt creator text editor or in notepad if is open) this flag is not working correctly and rendered window stays on background. I found windows this solution:
if(GetForegroundWindow() != reinterpret_cast<HWND>(winId())){ qDebug() << "Here is my problem"; }
but now If I set again it doesn't working and window anyway stays background.
setWindowFlags(Qt::WindowStaysOnTopHint );
Can someone help me?
-
@Giorgi said:
setWindowFlags(Qt::WindowStaysOnTopHint );
Works here on win 7, when set on the mainwindow. never falls behind anything.
Have you tried with a new project and only
setWindowFlags(Qt::WindowStaysOnTopHint );
in constructor ?also ctrl +r is run app with no debug. Guess you can call it render :)
-
MSDN said: To use SetWindowPos to bring a window to the top, the process that owns the window must have SetForegroundWindow permission.
eg.
#include <Windows.h>
SetForegroundWindow((HWND)winId());
setWindowFlags(Qt::WindowStaysOnTopHint);// in .pro
win32-g++:LIBS += libUser32
win32-msvc*:LIBS += User32.lib