Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Main window only stays on top (using WindowStaysOnTopHint) if breakpoint in code
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Main window only stays on top (using WindowStaysOnTopHint) if breakpoint in code

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 4.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stephenf555
    wrote on last edited by
    #1

    Hi folks,
    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:
    @void LEDControlWindow::updateWindowFlags()
    {
    Qt::WindowFlags flags = 0;
    flags = Qt::Widget; //always
    if(ui->checkBoxKeepOnTop->isChecked()) //set to keep on top
    flags |= Qt::WindowStaysOnTopHint;
    setWindowFlags(flags);
    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:
    @previewWindow->setWindowFlags(flags);
    previewWindow->show();@

    with the lines
    @this->setWindowFlags(flags);
    this->show();@

    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?

    Thanks,
    Stephen

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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();
      if (ui->checkBoxKeepOnTop->isChecked())
      flags |= Qt:: WindowStaysOnTopHint;
      else
      flags &= ~Qt:: WindowStaysOnTopHint;
      setWindowFlags(flags);@

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stephenf555
        wrote on last edited by
        #3

        Hi,
        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          By the way, what OS/Qt/Compiler combo are you using ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stephenf555
            wrote on last edited by
            #5

            Sorry, should have included those details.
            Qt5.3, Mingw 32bit (from QT5.3 kit), Win7

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Can you test that with the latest Qt 5.4 beta ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                stephenf555
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  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.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    stephenf555
                    wrote on last edited by
                    #9

                    Hi sierdzio,
                    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).

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved