Important: Please read the Qt Code of Conduct -

why setPen didn't work?

  • hi, here is a part of my source,
    why despite changing color pen,my shape is created in only one color blue??
    i want to some line is blue,some line is black...

            myPolygon << QPointF(-100, -100) << QPointF(100, -100)
                      << QPointF(100, 100) ;
             setPen(QPen(Qt::black, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
                  path.addRect(0,0,200, 200);
                  myPolygon = path.toFillPolygon();
                 setPen(QPen(Qt::blue, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
                  myPolygon << QPointF(0, 0) << QPointF(40,0)
                            << QPointF(0, 40) ;
                  path.addPolygon( myPolygon);

    this is link image shape:
    thanks for reply

  • Lifetime Qt Champion

    What are u calling setPen on?

    Paths do not store color and such information
    so Im not sure its possible to do with only 1 polygon.

    Maybe create a subclass of QGraphicsItem and paint it directly with
    qpainter::drawLine which supports colors very easy.