[SOLVED] Main window only stays on top (using WindowStaysOnTopHint) if breakpoint in code
I've a small application that I would like to keep on top of other windows when a checkbox is checked. For this I've made the below function:
Qt::WindowFlags flags = 0;
flags = Qt::Widget; //always
if(ui->checkBoxKeepOnTop->isChecked()) //set to keep on top
flags |= Qt::WindowStaysOnTopHint;
this->show(); //need to call this after alterations, otherwise window disappears
The WindowStaysOnTopHint only seems to have an effect if I put a breakpoint within this function (no change if I put the breakpoint elsewhere).
To test the issue, I've tried the Window Flags example and it works fine when altering the properties of the "preview window". I have then adjusted the example slightly to try to affect the properties of the main window. I've replaced the lines:
with the lines
With this small change made, I see the same behaviour...the window will stay on top only if I have it stop at a breakpoint within the updatePreview() function (where the above lines reside). With no breakpoint, no staying on top.
Can anyone recreate this behaviour with the Window Flags example and does anyone have an idea as to why I'm seeing this behaviour?
Currently, what you are doing is completely removing your widgets flags rather than append WindowStaysOnTopHint.
It should rather be something like
Qt::WindowFlags flags = windowFlags();
flags |= Qt:: WindowStaysOnTopHint;
flags &= ~Qt:: WindowStaysOnTopHint;
Hope it helps
Thanks for the response.
I've tried that approach too but the same behaviour occurs.
As with the previous approach, if I put a breakpoint on line 3 in the code above, the window does stay on top...if I don't, if doesn't.
If I put a breakpoint just at the last line and check the flags value, I can confirm that it is changing as expected, but unless the breakpoint is set at line 3 it has no effect.
Perhaps this is all just a weird dream.
By the way, what OS/Qt/Compiler combo are you using ?
Sorry, should have included those details.
Qt5.3, Mingw 32bit (from QT5.3 kit), Win7
Can you test that with the latest Qt 5.4 beta ?
Downloaded the 5.4 Alpha, but I have failed to build it successfully. When I run the configure command as described "here":http://qt-project.org/doc/qt-5/windows-building.html qmake crashes at the start of the build. I'm using mingw from the Qt5.3 package.
For now it's not a huge deal for me to fix...those using the software will probably never notice.
Qt 5.4 beta builds are already available - you do not need to compile those.
And if you want to, here are more thorough instructions: "link":http://qt-project.org/wiki/Building-Qt-5-from-Git#0cc5cbb2903cf6911ac1b6e3aa032572.
Thanks for the heads up...missed that on my first search for 5.4.
The issue seems to be resolved in 5.4.
Thanks all for the help.
Unrelated but FYI:
I do have an issue that when I launch the executable built on 5.4Beta outside of the QtCreator environment I get an error in Qt5Core.dll:
@The procedure entry point ZN14QLocalePrivate17bytearrayToDoubleEPKcPbS2 could not be located in the dynamic link library Qt5Core.dll.@
This issue occurs only for the 5.4 version of that dll...if I use the 5.3 version the program starts fine (however the window staying on top is an issue with 5.3).