Is there any way to move a QRect object from its current position?
There are many functions (moveTo
, moveLeft
, …), but all of them move the object from (0,0), and not from its current position.
If I need to move my object from its current position by 5 in X-direction, available methods moves it first to (0,0), and then to (5,0);
But I need to move it from its actual position.
int x_pos = item->rect.x();
int y_pos = item->rect.y();
x_pos -= 10;
y_pos -= 10;
item->rect.moveTo(x_pos, y_pos);
item->rect.setX(x_pos);
item->rect.setY(y_pos);
Just use
QRect::translate
. In your particular case that would be something like...Or, if you want to leave the original
QRect
unmodified...