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. Enabling anti-aliasing on QQuickItem or QSGGeometryNode
Forum Updated to NodeBB v4.3 + New Features

Enabling anti-aliasing on QQuickItem or QSGGeometryNode

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 125 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.
  • A Offline
    A Offline
    alex-zrythm
    wrote last edited by alex-zrythm
    #1

    Is there an easy way to have antialiased drawing in my custom QQuickItem-derived element? I only draw basic shapes but they look ugly by default. Here is my rendered triangle for example:

    Screenshot From 2025-06-19 13-37-15.png

    I saw some people online saying I need to write an opengl shader or something, but this seems way overkill for my use case, and it assumes opengl is used, which is not the case on Mac for example...

    I did do setAntialiasing(true) but without much benefit.

    I'm actually porting some of my QML code to make it more performant since i need to draw thousands of (simple) things. in my original QML code i used Shape/ShapePath with layer.samples = 4 and it looked nice enough:

     Shape {
                id: playheadShape
    
                width: control.playheadTriangleWidth
                height: control.playheadTriangleHeight
                x: transport.playhead.ticks * control.pxPerTick - width / 2
                y: control.height - height
                layer.enabled: true
                layer.samples: 4
    
                ShapePath {
                    fillColor: control.palette.text
                    strokeColor: control.palette.text
    
                    PathLine {
                        x: 0
                        y: 0
                    }
    
                    PathLine {
                        x: playheadShape.width
                        y: 0
                    }
    
                    PathLine {
                        x: playheadShape.width / 2
                        y: playheadShape.height
                    }
    
                }
    
            }
    

    It looked like this:

    Screenshot From 2025-06-19 13-41-12.png

    I basically want to mimic that in c++. I'm currently using QSGGeometryNode with a 2D QSGGeometry and a QSGFlatColorMaterial like this:

    QSGNode *
    RulerItem::updatePaintNode (QSGNode * oldNode, UpdatePaintNodeData * data)
    {
    // ...
      auto * playheadNode = new QSGGeometryNode;
      auto * playheadGeometry =
        new QSGGeometry (QSGGeometry::defaultAttributes_Point2D (), 3);
      playheadNode->setGeometry (playheadGeometry);
      playheadNode->setFlag (QSGNode::OwnsGeometry);
    
      auto * playheadMaterial = new QSGFlatColorMaterial;
      playheadMaterial->setColor (text_color_);
      playheadNode->setMaterial (playheadMaterial);
      playheadNode->setFlag (QSGNode::OwnsMaterial);
    
      QSGGeometry::Point2D * playheadVertices =
        playheadGeometry->vertexDataAsPoint2D ();
      playheadVertices[0] = playhead_vertices_[0];
      playheadVertices[1] = playhead_vertices_[1];
      playheadVertices[2] = playhead_vertices_[2];
    
      rootNode->appendChildNode (playheadNode);
    
      return rootNode;
    }
    

    Any ideas?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex-zrythm
      wrote last edited by
      #2

      I came across this example which uses QRhi (which avoids dependence on OpenGL directly like other people said to use): https://doc.qt.io/qt-6/qtquick-scenegraph-customrendernode-example.html

      It still seems overly complex but at least it looks like I'm in the right direction.

      Then, I came across this: https://doc.qt.io/qt-6/qrhirenderbuffer.html#sampleCount where I can set sampleCount to enable anti-aliasing. I don't really understand how QRhiRenderBuffer can be used, but somehow using QRhiRenderBuffer with sampleCount set to 4 or 8 in a QSGRenderNode -derived class seems like the proper way to have cross-platform hardware-accelerated anti-aliased drawing. Feel free to correct me.

      Until I find code examples showcasing how to bring all these functionalities together I have more important things to work on so I'll use QML Shape / ShapePath for now which makes it super easy to draw simple things (like an anti-aliased triangle).

      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