Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QQuickPaintedItem resize is not working as expected
Qt 6.11 is out! See what's new in the release blog

QQuickPaintedItem resize is not working as expected

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 490 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.
  • LorenDBL Offline
    LorenDBL Offline
    LorenDB
    wrote on last edited by
    #1

    I'm writing an app that uses a QQuickPaintedItem to 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 the MyQuickItem is 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.

    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