QQuickPaintedItem resize is not working as expected
-
I'm writing an app that uses a
QQuickPaintedItemto render to a QML object from C++. However, my code is not working as expected. The C++ code below is a complete, working example of what is going wrong:#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickPaintedItem> #include <QPainter> class MyQuickItem : public QQuickPaintedItem { Q_OBJECT public: explicit MyQuickItem(QQuickItem *parent = nullptr) : QQuickPaintedItem{parent} {} virtual void paint(QPainter *painter) { painter->fillRect(boundingRect(), QGradient::SpaceShift); } }; #include "main.moc" int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); qmlRegisterType<MyQuickItem>("MyApp", 1, 0, "MyQuickItem"); QQmlApplicationEngine engine; engine.loadData(R"( import QtQuick 2.15 import QtQuick.Window 2.15 import MyApp 1.0 Window { width: 500 height: 500 visible: true title: "test" MyQuickItem { anchors.fill: parent } } )"); return app.exec(); }At first, the application acts as expected: it creates a window filled with a gradient. However, resizing the window resizes the
MyQuickItem, which results in some strange behavior. If theMyQuickItemis resized to a size larger than its initial size, it goes blank. Otherwise, it renders more or less accurately to only part of itself (apparently scaling the output to a smaller size, according to my experimentation) while leaving artifacts all over the rest of itself.Images of what is going on can be found here.
I'm running openSUSE Tumbleweed; I tested on Qt 5.15.2 and 6.1.2.