1

I want to ask a question about can I resize QGraphicsItem without creating a class that inherits QGraphicsItem. For example, something like this:

void MyScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
   point = event->scenePos();
   if( ArrowCursor )
   {
      curItem = this->itemAt( point, view->transform() );
      if( curItem && !curItem->isSelected() )
      {
         curItem->update( 10,10, 100, 100 );
      }

   }
}
Oleksandr Verhun
  • 814
  • 1
  • 8
  • 23
  • As the docs state for update: "Schedules a redraw of the area covered by rect in this item. You can call this function whenever your item needs to be redrawn, such as if it changes appearance or size." So it's certainly not going to do it by calling update. – TheDarkKnight Jun 27 '14 at 15:54

1 Answers1

1
curItem->setTransform(QTransform::fromScale(2.0,2.0), true);

Offtopic: This is strange that you are doing this by subclassing QGraphicsScene.

Marek R
  • 32,568
  • 6
  • 55
  • 140
  • Thx, I tried it and all is nice and smooth. Well I'm beginner in this thing, so I subclassed QGraphicsScene to get scene coords of cursor with scenePos – Oleksandr Verhun Jun 27 '14 at 16:38
  • But one thing this method scales thickness of line, how do I escape that? – Oleksandr Verhun Jun 27 '14 at 16:43
  • 1
    @user3130843 : To avoid scaling of the line thickness, use `setCosmetic(true)` for the pen. Check out this question http://stackoverflow.com/questions/17075623/how-do-you-keep-qpen-pixel-width-the-same-when-zooming-in-a-qgraphicsview/23174260#23174260 – rpsml Jun 27 '14 at 18:49
  • Why do coords change every time I rescale it, I mean the new item coords, doesn't match top left coords of old item? – Oleksandr Verhun Jun 28 '14 at 12:01