Hey,
I'm having some strange behaviour while trying to scale a custom QGraphicsItem. Basically, I want to scale my item (its a simple QPainterPath thats shaped like a donut). I reimplemented the shape() function to make sure the shape as opposed to the bounding rectangle is the input sensitive region.
The item is centered at (0,0) in my scene. I want the user to click on the item, and drag towards (0,0) to scale down, and away (0,0) to scale up. Since my shape is a donut, this amounts to dragging towards or away from the center of the shape. I implemented this by overloading 'mouseMoveEvent' and getting mouse x,y coordinates to calculate the distance from (0,0), and then based on that, set the scale of the object.
So if I just calculate the distance, and move my mouse back and forth, this works as expected... my distance smoothly increases and decreases as I move the mouse around. If I actually scale the shape while moving the mouse though, it jumps back and forth (the distance), pixel to pixel... causing the scale to jump around as well... I can't figure out why.
I'd appreciate any help figuring out what's going on!
{
double lkmx = event->pos().x();
double lkmy = event->pos().y();
double cen_dist = sqrt(pow(lkmx,2) + pow(lkmy,2));
qDebug() << "% distance from center: " << cen_dist/_radtyp << "\n";
// so if I uncomment the lines below qDebug()'s output will jump around, otherwise it'll be
// as expected
//_zoomfactor = cen_dist/_radtyp;
// this->setTransform(QTransform::fromScale(_zoomfactor, _zoomfactor), false);
}
void Ring::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
double lkmx = event->pos().x();
double lkmy = event->pos().y();
double cen_dist = sqrt(pow(lkmx,2) + pow(lkmy,2));
qDebug() << "% distance from center: " << cen_dist/_radtyp << "\n";
// so if I uncomment the lines below qDebug()'s output will jump around, otherwise it'll be
// as expected
//_zoomfactor = cen_dist/_radtyp;
// this->setTransform(QTransform::fromScale(_zoomfactor, _zoomfactor), false);
}
To copy to clipboard, switch view to plain text mode
Bookmarks