PDA

View Full Version : Problem in zooming qgraphicsScene by re-scale the pixmap



fulin
21st February 2011, 11:25
I'm using QGraphicsView QGraphicsScene to display an image. The code looks like

QPixmap pixmap = QPixmap::fromImage(*myQImage);
QPixmap scaledPixmap = pixmap.scaled(scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QGraphicsScene *s = ui->graphicsView->scene();
s->clear();
s->addPixmap(scaledPixmap);

To increase the (QSize) scale from 1, no problem. But when I decease the scale, for example from 5 to 1, then there will be two white boards on the right and down sides of the graphicsView. It seems that the graphicsScene doesn't shrinking.

Is there any command to do a "clean" or "reset" of the graphicsView or the graphicsScene or the similar?

Thank you very much in advance!

SixDegrees
21st February 2011, 12:21
Try getting a pointer to the QGraphicsPixmapItem returned by addPixmap, and reset its TransformationMode from FastTransformation to SmoothTransformation.

You might also try calling QGraphicsScene->update() to invoke a complete repaint.

fulin
21st February 2011, 12:46
Do you mean something like

QGraphicsPixmapItem pixmapItem = new QGraphicsPixmapItem(scaledPixmap, this,s);
pixmapItem.setTransformationMode(Qt::TransparentMo de);

or

scene->update()

The later seems not work and for the first one, could you please show me in a little more detailed?

Thank you.