[Qt-interest] QGraphicsItem::setTransformOriginPoint BUG

Cole, Derek dcole at integrity-apps.com
Thu Mar 10 23:19:21 CET 2011


Hello,

I have created my own class by extending QGraphicsItem and I want to make it so that when someone does a wheel even while over this item, it scales.

This way, i can have multiple items in a scene, and scale each of them in and out as I please.

The problem is, I want the item to scale under the mouse cursor, much like google maps does. That is, a move forward will keep panning the image and scaling it, so taht the area in the vicinity around my mouse pointer is always in view.

void ImagePixmapItem::wheelEvent ( QGraphicsSceneWheelEvent * event ){

    update();
    qreal factor = 1.2;
    if (event->delta() < 0)
      factor = 1.0 / factor;

    scale(factor, factor);
    
    scaleFactor *=factor;
    this->scene()->setSceneRect(0,0,this->boundingRect().width(), this->boundingRect().height());
    
}

This is the code I am using to do the scale. The problem is, it always seems to be scaling from the top left corner. Well, this is undesirable, beacuse if I scale in or out too much, eventually my  area of interest around the mouse pointer has moved off the screen, and I have to either scroll manually or pan to the location, zoom, pan, etc, until i get to the desired level.

I tried to use the  QGraphicsItem::setTransformOriginPoint, but no matter what values I put in there, it still seems to scale and such from the top left.

What can I add to that code I posted to get the desired effect?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110310/93657bf2/attachment.html 


More information about the Qt-interest-old mailing list