Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

Efficient custom shapes in Qt Quick

Because rectangles, even rounded ones, can only get you so far.

Sector {
    id: baseSector
    color: "white"; 
    endColor: "black";
    outerColor: "red"; 
    outerEndColor: "green";
    outerRadius: (parent.width / 2) - 40
    anchors.centerIn: parent
    innerRadius: outerRadius - thickness.value
    startAngle: -110
    spanAngle: spanAngle.value
    borderColor: "black"; 
    borderWidth: 1.0
}
int vertexCount = .... compute number of unique vertices
int indexCount = ... compute number of triangles * 3;
node = new QSGGeometryNode;
geom = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(),
                       vertexCount, indexCount);
geom->setIndexDataPattern(QSGGeometry::StaticPattern);
geom->setDrawingMode(GL_TRIANGLES);
node->setGeometry(geom);
node->setFlag(QSGNode::OwnsGeometry);
QSGGeometry::TexturedPoint2D *points = geom->vertexDataAsTexturedPoint2D();
// computing s & t not shown here for simplicity
points[i].set(innerRadius * cos(angleInRad),
              innerRadius * sin(angleInRad), s, t);
quint16* indices = geom->indexDataAsUShort();
// three sequential entries in 'indices' define a
// single triangle, here using vertices 4, 6 and 3
indices[i] = 4;
indices[i+1] = 6;
indices[i+2] = 3;
geom->markIndexDataDirty();
geom->markVertexDataDirty();
node->markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial);

11 Comments

26 - Sept - 2018

zahraee

26 - Sept - 2018

James Turner

29 - Sept - 2018

zahraee

5 - Oct - 2018

James Turner

25 - Aug - 2021

Nicolas Fella

28 - Sept - 2018

Patrick José Pereira

28 - Sept - 2018

James Turner

16 - Aug - 2019

Mousavi

16 - Aug - 2019

Mousavi

3 - May - 2020

S.M.Mousavi

5 - May - 2020

James Turner

JamesTurner

James Turner

Senior Software Engineer & Teamlead