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

void QPainterPath::addRect ( const QRectF rectangle  ) 

Adds the given rectangle to this path as a closed subpath.

The rectangle is added as a clockwise set of lines. The painter path's current position after the rectangle has been added is at the top-left corner of the rectangle.

100% qpainterpath-addrectangle.png

        QLinearGradient myGradient;
        QPen myPen;
        QRectF myRectangle;

        QPainterPath myPath;
        myPath.addRect(myRectangle);

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

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

Definition at line 959 of file qpainterpath.cpp.

References QRectF::height(), QRectF::isNull(), moveTo(), QRectF::width(), QRectF::x(), and QRectF::y().

Referenced by addRect(), addRegion(), addRoundRect(), addText(), QGraphicsItem::collidesWithPath(), QTextLayout::draw(), QTextLine::draw(), QCDEStyle::drawControl(), QRasterPaintEngine::drawImage(), QPaintEngine::drawRects(), QPainter::drawRects(), QRasterPaintEngine::drawTiledPixmap(), QGraphicsView::items(), QGraphicsScene::items(), QGraphicsView::paintEvent(), QPainter::setClipRect(), QGraphicsTextItem::shape(), QGraphicsItem::shape(), QGraphicsSimpleTextItem::shape(), and QGraphicsRectItem::shape().

{
#ifndef QT_NO_DEBUG
    if (qt_is_nan(r.x()) || qt_is_nan(r.y()) || qt_is_nan(r.width()) || qt_is_nan(r.height()))
        qWarning("QPainterPath::addRect: Adding rect where a parameter is NaN, results are undefined");
#endif
    if (r.isNull())
        return;

    ensureData();
    detach();

    d_func()->elements.reserve(d_func()->elements.size() + 5);
    moveTo(r.x(), r.y());

    Element l1 = { r.x() + r.width(), r.y(), LineToElement };
    Element l2 = { r.x() + r.width(), r.y() + r.height(), LineToElement };
    Element l3 = { r.x(), r.y() + r.height(), LineToElement };
    Element l4 = { r.x(), r.y(), LineToElement };

    d_func()->elements << l1 << l2 << l3 << l4;
    d_func()->require_moveTo = true;
}


Generated by  Doxygen 1.6.0   Back to index