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

void QPainter::drawPixmap ( const QRectF target,
const QPixmap pixmap,
const QRectF source 
) [inherited]

Draws the rectangular portion source of the given pixmap into the given target in the paint device.

100%

    QRectF target(10.0, 20.0, 80.0, 60.0);
    QRectF source(0.0, 0.0, 70.0, 40.0);
    QPixmap pixmap(":myPixmap.png");

    QPainter(this);
    painter.drawPixmap(target, image, source);

See also:
drawImage()

Definition at line 4090 of file qpainter.cpp.

References QPainter::drawRect(), QPainter::fillRect(), QRectF::height(), QPixmap::height(), QPainter::isActive(), QPixmap::isNull(), QPixmap::isQBitmap(), QPainter::restore(), QPainter::save(), QPainter::scale(), QPainter::setBackgroundMode(), QPainter::setBrush(), QPainter::setBrushOrigin(), QPainter::setPen(), QPainter::translate(), QPixmap::width(), QRectF::width(), QRectF::x(), and QRectF::y().

Referenced by Q3CanvasSprite::draw(), Q3Canvas::drawBackground(), QWindowsStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QMotifStyle::drawControl(), QWindowsStyle::drawControl(), QWindowsXPStyle::drawControl(), QCommonStyle::drawControl(), QItemDelegate::drawDecoration(), QPainter::drawImage(), QStyle::drawItemPixmap(), QPainter::drawPixmap(), QCommonStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QPicture::exec(), Q3ListBoxPixmap::paint(), Q3TableItem::paint(), QGraphicsSvgItem::paint(), QGraphicsPixmapItem::paint(), Q3ListViewItem::paintCell(), Q3ComboBox::paintEvent(), QGraphicsView::paintEvent(), Q3IconViewItem::paintItem(), QGraphicsView::scrollContentsBy(), QPlastiqueStyle::standardIconImplementation(), QWindowsStyle::standardIconImplementation(), QCleanlooksStyle::standardIconImplementation(), QCleanlooksStyle::standardPixmap(), QWindowsStyle::standardPixmap(), and QPlastiqueStyle::standardPixmap().

{
#if defined QT_DEBUG_DRAW
    if (qt_show_painter_debug_output)
        printf("QPainter::drawPixmap(), target=[%.2f,%.2f,%.2f,%.2f], pix=[%d,%d], source=[%.2f,%.2f,%.2f,%.2f]\n",
               r.x(), r.y(), r.width(), r.height(),
               pm.width(), pm.height(),
               sr.x(), sr.y(), sr.width(), sr.height());
#endif

    Q_D(QPainter);
    if (!isActive() || pm.isNull())
        return;

    qreal x = r.x();
    qreal y = r.y();
    qreal w = r.width();
    qreal h = r.height();
    qreal sx = sr.x();
    qreal sy = sr.y();
    qreal sw = sr.width();
    qreal sh = sr.height();

    // Sanity-check clipping
    if (sw <= 0 || sw + sx > pm.width())
        sw = pm.width() - sx;

    if (sh <= 0 || sh + sy > pm.height())
        sh = pm.height() - sy;

    if (sx < 0) {
        x -= sx;
        sw += sx;
        sx = 0;
    }

    if (sy < 0) {
        y -= sy;
        sh += sy;
        sy = 0;
    }

    if (w < 0)
        w = sw;
    if (h < 0)
        h = sh;

    if (w == 0 || h == 0 || sw <= 0 || sh <= 0)
        return;

    // Emulate opaque background for bitmaps
    if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap()) {
        fillRect(QRectF(x, y, w, h), d->state->bgBrush.color());
    }

    d->updateState(d->state);

    if (d->state->txop > QPainterPrivate::TxTranslate
        && !d->engine->hasFeature(QPaintEngine::PixmapTransform)
        || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))
        || ((sw != w || sh != h) && !d->engine->hasFeature(QPaintEngine::PixmapTransform)))
    {
        save();
        translate(x, y);
        scale(w / sw, h / sh);
        setBackgroundMode(Qt::TransparentMode);
        setBrush(QBrush(d->state->pen.color(), pm));
        setPen(Qt::NoPen);
        setBrushOrigin(QPointF(-sx, -sy));

        drawRect(QRectF(0, 0, sw, sh));
        restore();
    } else {
        if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
            x += qRound(d->state->matrix.dx());
            y += qRound(d->state->matrix.dy());
        }
        d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh));
    }
}


Generated by  Doxygen 1.6.0   Back to index