FramelessWindowHint window not responding with qml Widget
-
Hello,
I have embedded a QML window within a QWidget to display it in a QMainWindow. However, when I set the window flag as FramelessWindowHint and click outside the application on my other screen, and then click inside my Qt application again, the console logs "clicked" but there is no change in the color of my rectangle. This issue only occurs when using the FramelessWindowHint flag.main.cpp code
int main(int argc, char* argv[]) { QApplication app(argc,argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); engine.load(url); MainWindow* mainWin = new MainWindow(&engine); mainWin->setWindowFlags(Qt::FramelessWindowHint | Qt::Window); mainWin->show(); return app.exec(); }MainWindow.cpp code
MainWindow::MainWindow(QQmlApplicationEngine* engine, QWidget* parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); QScreen *screen = QGuiApplication::primaryScreen(); QSize screenSize = screen->availableSize(); this->setFixedSize(screenSize); ui->centralwidget->setFixedSize(screenSize); // qml window QWindow *qmlWindow = qobject_cast<QWindow*>(engine->rootObjects().at(0)); QWidget* testWidget = QWidget::createWindowContainer(qmlWindow, this); testWidget->setContentsMargins(0,0,0,0); testWidget->setFixedSize(screenSize); }main.qml code
Window { width: Screen.width height: Screen.height Rectangle { id: id_rect width: 200 height: 300 anchors.centerIn: parent color: "blue" property bool isBlue: true MouseArea { anchors.fill: parent onClicked: { console.log("clicked"); id_rect.color = id_rect.isBlue ? "red" : "blue"; id_rect.isBlue = !id_rect.isBlue; } } } }Thanks for your help.