Search code examples
c++qtqmlhighdpi

Running a QML program on my external monitor results in weird artefacts until I move the window


I have a weird bug in Qt + QML when I run my program on a highres external monitor. I have a small minimal example and when I run it on my laptop monitor with the settings 2560x1440, scaling 125%, the output is as expected:

expected result

But when I run the program on my external monitor with the settings 2560x1440 and scaling 100% the program looks like this. And weirdly it only does so until it receives any kind of window event (moving, changing the size) then it snaps straight back to what it should look like above.

enter image description here

Even weirder, if I set my laptop scaling to 100%, opening the program on the external monitor works as expected... It does seem like a Qt bug to me... Or are there any settings I am missing? Has anybody experiencend something similar?

I run the following code using Qt 6.3.1 (taken more or less from the Qt examples):

// main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    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);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
import QtQuick

Window {
    id: appWindow

    width: 1920
    height: 1080

    visible: true
    title: qsTr("Test")
    color: "red"

    Rectangle {
        id: topBar

        width: appWindow.width
        height: 60
        color: "grey"
    }

    Rectangle {
        anchors.top: topBar.bottom
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.left: parent.left

        color: "black"
    }
}

Solution

  • I updated to Qt 6.4.2 and now the problem seems to be gone, so I am assuming they fixed it :)