Important: Please read the Qt Code of Conduct -

need help in QSGGeometry

  • Hi,

    I would like to know some advise on creating a custom geometry using scene graph.
    My problem is I don't know how to fill the custom geometry with color.
    And how to add text on geometry node without using QPainter, is it possible?

    Below is my code:

    QSGNode *TabBar::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
        QSGNode *root = static_cast<QSGNode *>(oldNode);
        if(!root) root = new QSGNode;
        QSGGeometry *geometry;
        geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 6);
        geometry->vertexDataAsPoint2D()[0].set(20, 40);
        geometry->vertexDataAsPoint2D()[1].set(0, 0);
        geometry->vertexDataAsPoint2D()[2].set(100, 0);
        geometry->vertexDataAsPoint2D()[3].set(120, 40);
        geometry->vertexDataAsPoint2D()[4].set(100, 80);
        geometry->vertexDataAsPoint2D()[5].set(0, 80);
        node = drawPolygon(geometry, Qt::red);
    QSGNode *TabBar::drawPolygon(QSGGeometry *geometry, const QColor &color)
        QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
        QSGGeometryNode *node = new QSGGeometryNode;
        return node;

    I managed to fill the geometry using GL_TRIANGLE_FAN drawingMode and by modifying the vertices which will start on the vertex which will create a triangle without intersecting each other.

    The problem now is how to draw a text on the geometry.

    Please advise. TIA.

  • update:

    Found this thread that there is no available text/glyph node yet for text rendering on the scene graph node.

    It was suggested (but not ideal) to draw text using QPainter on QImage and show on texture.
    Any advise how to convert the image into texture? I can't find any example. Thanks.

Log in to reply