class WindowDraw : public QGraphicsView{ ... private: QGraphicsScene *scene; ...}
void YourScene::drawBackground( QPainter* p, const QRectF& clip ){ if( !bg_image_ ) // QImage* bg_image_ - предварительно загруженная картинка { QGraphicsScene::drawBackground( p, clip ); return; } p->eraseRect( clip ); QMatrix wm( p->worldMatrix() ); if( wm.m11() != 1 && clip.intersects( bg_image_->rect() ) ) { QImage img; QRectF c( clip ); if( wm.m11() > 1 ) c.adjust( -1, -1, 1, 1 ); qreal cx = c.x(); qreal cy = c.y(); qreal cw = qMax( 16., c.width() ); qreal ch = qMax( 16., c.height() ); if( cx < 0 ) { cw += cx; cx = 0; } if( cy < 0 ) { ch += cy; cy = 0; } cw = qMin( cw, bg_image_->width() - cx ); ch = qMin( ch, bg_image_->height() - cy ); img = bg_image_->copy( QRectF( cx, cy, cw, ch ).toRect() ); cw = qRound( cw * wm.m11() ); ch = qRound( ch * wm.m11() ); img = img.scaled( (int) cw, (int) ch, Qt::IgnoreAspectRatio, /*wm.m11() > .8 ? Qt::SmoothTransformation :*/ Qt::FastTransformation ); p->setWorldMatrix( QMatrix( 1, 0, 0, 1, wm.dx(), wm.dy() ) ); p->drawImage( QPointF( cx * wm.m11(), cy * wm.m11() ), img ); p->setWorldMatrix( wm ); } else { p->drawImage( QPointF( clip.x(), clip.y() ), *bg_image_, QRectF( clip.x(), clip.y(), qMin( clip.width(), qreal( bg_image_->width() ) ), qMin( clip.height(), qreal( bg_image_->height() ) ) ) ); }}