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. Implementing updatePaintNode causes other QML elements to also draw incorrectly
Qt 6.11 is out! See what's new in the release blog

Implementing updatePaintNode causes other QML elements to also draw incorrectly

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 1 Posters 2.6k 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.
  • Q Offline
    Q Offline
    qttester5
    wrote on last edited by
    #1

    I am trying to learn how to do basic drawing with a subclassed QQuickItem. Using this simple code to draw a line, my QML element does in fact draw a line, but having an implementation of this function also causes other, unrelated QML elements (which are not subclassed in C++) to draw incorrectly by moving their positions, layout and clipping. Apparently the Scene Graph is getting messed up by just having one single element with custom drawing in it:

    @ QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data){

            QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2);
            geometry->setDrawingMode(GL_LINES);
            geometry->setLineWidth(3);
            geometry->vertexDataAsPoint2D()[0].set(0, 0);
            geometry->vertexDataAsPoint2D()[1].set(width(), height());
    
            QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
            material->setColor(QColor(255, 0, 0));
    
            QSGGeometryNode *node = new QSGGeometryNode;
            node->setGeometry(geometry);
            node->setFlag(QSGNode::OwnsGeometry);
            node->setMaterial(material);
            node->setFlag(QSGNode::OwnsMaterial);
    
            delete oldNode;
            return node;
    
    
        }@
    

    I'm guessing the cause of this problem lies outside this function. If I simply comment out this line in the class's constructor, the above function of course isn't called and everything returns to normal:

    @setFlag(QQuickItem::ItemHasContents, true);@

    What could cause the Qt Quick SceneGraph to get all distorted when trying to do this?

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qttester5
      wrote on last edited by
      #2

      It looks like the drawing code itself is responsible for messing up other QML elements, which surprises me. If my implementation of this function only says return oldNode; and nothing else, the rest of my QML scene looks fine. I am following a very simple official example for drawing a line and this code is copied over from that. I can't see anything that should cause this behavior.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qttester5
        wrote on last edited by
        #3

        I have discovered that @geometry->setLineWidth(3); @in the code above extends to other QML elements and can distort them, even if those other QML elements are "normal" QML elements (with no QQuickItem subclass beneath them). This seems odd to me that you could affect other elements and I wonder if it is a bug? The documentation says that this function should only affect the current element, but that is not my experience. Can anyone weigh in on why @geometry->setLineWidth(3); @has such unwieldy power?

        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