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 );
}
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 );
}