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. Unset Qt::WindowStaysOnTopHint flag problem
Forum Updated to NodeBB v4.3 + New Features

Unset Qt::WindowStaysOnTopHint flag problem

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 7.3k 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.
  • T Offline
    T Offline
    tomi127
    wrote on last edited by
    #1

    Hi, i have problem with Qt::WindowStaysOnTopHint flag. One set this flag cannot be unset (window always is on top). There is a small piece of example code:
    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_pushButton_clicked(bool checked)
    {
    if(checked) {
    setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
    } else {
    setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);

    }
    
    show();
    

    }
    @

    If i check the button window correctly will stay on top. But when i unckeck the button window still stays on top... What's going wrong?

    Problem exist in WindowFlags example too.

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

      Hi,

      What OS / Qt version 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
      • T Offline
        T Offline
        tomi127
        wrote on last edited by
        #3

        Hi.
        I'm using Qt 5.1.0 (32 bit) and Windows 7 HP x64.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vittalonline
          wrote on last edited by
          #4

          @
          if(checked) {
          setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
          update();
          }
          else {
          setWindowFlags(windowFlags()|Qt::WindowStaysOnBottomHint);
          update();
          }
          @

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tomi127
            wrote on last edited by
            #5

            I changed your code and it works OK, but i'm don't sure it is a good practice. Anyway it works :)
            @if(disable) {
            setWindowFlags((windowFlags() & ~Qt::WindowStaysOnBottomHint) | Qt::WindowStaysOnTopHint);
            } else {
            setWindowFlags((windowFlags() & ~Qt::WindowStaysOnTopHint) | Qt::WindowStaysOnBottomHint);
            }

            show();
            raise();@
            
            1 Reply Last reply
            0
            • S Offline
              S Offline
              stephenf555
              wrote on last edited by
              #6

              -Had this same issue...thanks for the code above.-

              -Not sure why unsetting the WindowStaysOnTopHint doesn't have the expected effect...I don't think the documentation alludes to this.-

              After posting this noted that I only get the desired effect if a insert a breakpoint into the code. As this is slightly different to the question asked here I've posted it as a new question at http://qt-project.org/forums/viewthread/48218/

              Stephen

              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