Results 1 to 3 of 3

Thread: Problem in zooming qgraphicsScene by re-scale the pixmap

  1. #1
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    5

    Default Problem in zooming qgraphicsScene by re-scale the pixmap

    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!

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Problem in zooming qgraphicsScene by re-scale the pixmap

    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.

  3. #3
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    5

    Default Re: Problem in zooming qgraphicsScene by re-scale the pixmap

    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.

Similar Threads

  1. How to scale pixmap to fit
    By Splatify in forum Newbie
    Replies: 5
    Last Post: 21st April 2011, 16:45
  2. Replies: 3
    Last Post: 16th April 2010, 07:56
  3. AddLine over QGraphicsscene Pixmap
    By Qt Coder in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2009, 08:12
  4. Replies: 0
    Last Post: 3rd February 2009, 13:16
  5. How to copy pixmap and keep scale ratio?
    By Teerayoot in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2007, 11:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.