0

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,

here is the code:

    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);
Soukaina
  • 1
  • 3

1 Answers1

1

Just use QRect::translate. In your particular case that would be something like...

item->rect.translate(-10, -10);

Or, if you want to leave the original QRect unmodified...

auto new_rect = item->rect.translated(-10, -10);
G.M.
  • 12,232
  • 2
  • 15
  • 18