Unset Qt::WindowStaysOnTopHint flag problem
-
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.
-
Hi,
What OS / Qt version are you using ?
-
@
if(checked) {
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
update();
}
else {
setWindowFlags(windowFlags()|Qt::WindowStaysOnBottomHint);
update();
}
@ -
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();@
-
-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