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. FramelessWindowHint window not responding with qml Widget
Forum Updated to NodeBB v4.3 + New Features

FramelessWindowHint window not responding with qml Widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 255 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.
  • J Offline
    J Offline
    JonC
    wrote on last edited by
    #1

    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.

    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