Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

void QPainterPath::addPolygon ( const QPolygonF polygon  ) 

Adds the given polygon to the path as an (unclosed) subpath.

Note that the current position after the polygon has been added, is the last point in polygon. To draw a line back to the first point, use the closeSubpath() function.

100% qpainterpath-addpolygon.png

        QLinearGradient myGradient;
        QPen myPen;
        QPolygonF myPolygon;

        QPainterPath myPath;
        myPath.addPolygon(myPolygon);

        QPainter painter(this);
        painter.setBrush(myGradient);
        painter.setPen(myPen);
        painter.drawPath(myPath);

See also:
lineTo(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1012 of file qpainterpath.cpp.

References QVector< T >::at(), QVector< T >::first(), QVector< T >::isEmpty(), moveTo(), QVector< T >::size(), QPointF::x(), and QPointF::y().

Referenced by QCommonStyle::drawControl(), QPolygon::intersected(), QPolygonF::intersected(), QGraphicsView::items(), QGraphicsScene::items(), QGraphicsView::mouseMoveEvent(), QGraphicsView::render(), QGraphicsPolygonItem::shape(), QPolygonF::subtracted(), QPolygon::subtracted(), QPolygon::united(), and QPolygonF::united().

{
    if (polygon.isEmpty())
        return;

    ensureData();
    detach();

    d_func()->elements.reserve(d_func()->elements.size() + polygon.size());

    moveTo(polygon.first());
    for (int i=1; i<polygon.size(); ++i) {
        Element elm = { polygon.at(i).x(), polygon.at(i).y(), LineToElement };
        d_func()->elements << elm;
    }
}


Generated by  Doxygen 1.6.0   Back to index