PDA

View Full Version : Image/Pixmap after scaling parcelled into 4 pieces.



Douglish
19th February 2011, 00:21
Hi all, I have a board desk and using some image as background, it's saved in svg file and I render it from there to a pixmap/image. Then I scale it to size of QGraphicsView on renderEvent. But a problem is that pixmap/image is parcelled after the scaling.

There is a screenshot of the problem as attachment.

I would love to have the background in one piece not parcelled, what am I doing wrong?

Here's the renderEvent implementation:


void kMancalaBoard::resizeEvent ( QResizeEvent *event ) {
qDebug("Resize event ... ");
QSize sz(400, 300);

qDebug("Width: %d, Height: %d", sz.width(), sz.height());

QPixmap bg ( QSize(400, 200) );
QPainter bgPainter ( &bg );

if ( m_renderer->elementExists ( QString ( "background" ) ) ) {
qDebug ( "Rendering" );
m_renderer->render ( &bgPainter, QString ( "background" ), QRectF ( QPointF ( 0,0 ), sz ) );
} else {
qDebug ( "No background found" );
}

QSize hint = size();
qDebug("Width: %d, Height: %d", hint.width(), hint.height());

QBrush br ( bg.scaled(hint, Qt::IgnoreAspectRatio, Qt::SmoothTransformation) );
m_scene->setBackgroundBrush ( br );

QGraphicsView::resizeEvent ( event );

}

Lykurg
19th February 2011, 07:50
Wow, what's about reimp the paint method of your view and print the images directly? the painters drawPixmap method will scale the image on its own.

Douglish
19th February 2011, 09:28
I'm not sure how to do that and if it would help. Problem is in setting setBackgroundBrush, if I put a image to scene as scene->addPixmap(...) image is ok. So problem is somewhere in scene painting with brush.

Added after 23 minutes:

Finally I solved that by reimplementing drawBackground of the view as you suggested.



void kMancalaBoard::drawBackground(QPainter *painter, const QRectF &rect) {
if ( m_renderer->elementExists ( QString ( "background" ) ) ) {
qDebug ( "Rendering" );
m_renderer->render ( painter, QString ( "background" ), rect);
} else {
qDebug ( "No background found" );
}
}