I have a basic qml application QWindow that already defines the property flags. I would like to change/update the property flags from main.cpp so that it is not frameless. I know I can do it directly in QML but I'd like to change it dynamically without re-compiling. I have found a number of examples but none show how to do this after using QQmlApplicationEngine::load() method. I posted my code below and I am able to see the current flags decimal value 2048 or hex value 0x800. According to documentation the hex value of 0x800 refers to Qt::FramelessWindowHint which is the current setting. I have tried to modify the flags property but the window doesn't update.
// Main.qml
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
id: window
objectName: "window"
...
flags: Qt.FramelessWindowHint
...
}
// main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QWindow>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.addImportPath("qrc:/");
QObject::connect(&engine, &QQmlApplicationEngine::quit, &app,
&QGuiApplication::quit);
const QUrl url(QStringLiteral("qrc:/Main.qml"));
QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated, &app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl) QCoreApplication::exit(-1);
QVariant obj2 = obj->property("flags");
if (obj2.isValid()) {
Qt::WindowFlags flags = qvariant_cast<Qt::WindowFlags>(obj2);
flags &= ~Qt::FramelessWindowHint;
auto *tmp = dynamic_cast<QWindow*>(obj);
tmp->setFlags(flags);
tmp->show();
}
},
Qt::QueuedConnection);
engine.load(url);
return app.exec();
}


obj->setProperty("flags", 0);to just zero out the flag but doesn't work either. - slayerobj->setProperty("flags", Qt::Window);when I want to override theQt.FramelessWindowHintflag. - slayer