Important: Please read the Qt Code of Conduct -

QML type to draw with QPainter

  • Hello!
    In QML documentation I found an example of custom type (defined from C++) to draw on it with QPainter:

    #include <QtQuick/QQuickPaintedItem>

    class PieChart : public QQuickPaintedItem
    void paint(QPainter *painter);


    @void PieChart::paint(QPainter painter)
    QPen pen(m_color, 2);
    painter->setRenderHints(QPainter::Antialiasing, true);
    painter->drawPie(boundingRect().adjusted(1, 1, -1, -1), 90
    16, 290*16);

    How can I derive a type to draw (e.g. a line) on it asynchronously with QPainter? Thanks!

  • It is not really clear what you mean by asynchronously here. QQuickPainted item is already implicitly painted asynchronously relative to the scenegraph rendering depending on which platform it is running on. Most likely it is exactly what you should be using to draw a line using QPainter. What makes you think it is unsuitable?

  • You can use the QPainter or to use openGL API for paint

Log in to reply