[Qt-interest] QGraphicsItem::setTransformOriginPoint BUG

Malyushytsky, Alex alex at wai.com
Tue Mar 15 23:12:33 CET 2011


Please use mailing list to ask questions instead of sending e-mails directly.

>> Would I do this before or after I have transformed the item? I tried playing around with this some, but no good results so far.

I have not used QGraphicsItem for a while, so I suggested you to find and an answer - the ways I could suggest probably are obsolete.
For example scale() as I believe is obsolete in Qt 4.6.
More of that newer Qt versions might give you better way to achieve what you want.
For example:
 - setting transformOriginPoint to middle point of pixmap before scaling may be just what you need:
void QGraphicsItem::setTransformOriginPoint ( const QPointF & origin )

- or using transform specifying center of transformation instead of calling scale() as in your example:

 // Scale an item by 3x2 from (x, y)
 item->setTransform(QTransform().translate(x, y).scale(3, 2).translate(-x, -y));


Alex


From: Cole, Derek [mailto:dcole at integrity-apps.com] 
Sent: Tuesday, March 15, 2011 12:26 PM
To: Malyushytsky, Alex
Subject: RE: [Qt-interest] QGraphicsItem::setTransformOriginPoint BUG

Would I do this before or after I have transformed the item? I tried playing around with this some, but no good results so far.


-----Original Message-----
From: qt-interest-bounces+dcole=integrity-apps.com at qt.nokia.com on behalf of Malyushytsky, Alex
Sent: Fri 3/11/2011 7:50 PM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] QGraphicsItem::setTransformOriginPoint BUG

QGraphicsItem is scaled relative to the item local coordinate system origin.
If it is in the top left corner (which I believe is normal for some of the item types like QPixmapGraphicsItem ) you get what you observe.
In case of the above you may try to play with setOffest()

Alex


From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of Cole, Derek
Sent: Thursday, March 10, 2011 2:19 PM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] QGraphicsItem::setTransformOriginPoint BUG



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?


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."



More information about the Qt-interest-old mailing list