Important: Please read the Qt Code of Conduct -

How to draw filled polygon on QGraphicsScene

  • I want to draw a polygon filled with a specific color on QGraphicsScene. Then I use the following codes:

    QPolygonF poly;
    poly << QPointF(10, 10) << QPointF(10, 50) << QPointF(30, 70 )<< QPointF(60, 50) << QPointF(50, 10);
    QBrush brush;
    QPen pen(Qt::green);
    QGraphicsScene graphics_scene_ = new QGraphicsScene(0,0,200,200);
    graphics_scene_->addPolygon(poly, pen, brush);

    However I only get a hollow polygon with green border, but without red fill inside the polygon.
    How can I fix it?

  • I've finally figured out how to do.
    Just adding



Log in to reply