Results 1 to 2 of 2

Thread: QGraphicsItem scale around arbitrary origin - problem with scenePos

  1. #1
    Join Date
    Aug 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsItem scale around arbitrary origin - problem with scenePos

    Greetings,
    I have tried to scale QGraphicsItem (QGraphicsPixmapItem) around center point of pixmap (with setTransform(QTransform().translate(x, y).scale(sx,sy).translate(-x, -y)) like in documentation). Now if I try to save scenePos and then reproduce it the final position of that item is different than saved position. What am I missing?

    Regards,
    MadBear

  2. #2
    Join Date
    Aug 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem scale around arbitrary origin - problem with scenePos

    Greetings,
    To further explain what is the problem:

    1. Creation of item
    Qt Code:
    1. QGraphicsPixmap *pix=new QGraphicsPixmap();
    2. pix->setPixmap(somePixmap);
    3. scene->addItem(pix);
    To copy to clipboard, switch view to plain text mode 

    2. Mouse wheel event on scene
    Qt Code:
    1. resetTransform();
    2. QRectF brc=boundingRect();
    3. setTransform(QTransform::fromTranslate(-brc.width()/2.0, -brc.height()/2.0)*QTransform::fromScale(sx, sy).rotate(alpha)*QTransform::fromTranslate(brc.width()/2.0, brc.height()/2.0), true);
    To copy to clipboard, switch view to plain text mode 

    3. Do something with scene position of item
    Qt Code:
    1. QList<QGraphicsItem*> sel=selectedItems();
    2. int i;
    3. for(i=0;i<sel.count();i++)
    4. {
    5. QPointF xy=sel[i]->scenePos();
    6. sel[i]->setPos(xy.x(),xy.y()-tranStep); //here the position should only change for tranStep but it does not (the change is much larger and rotation also affects change in position)
    7. }
    To copy to clipboard, switch view to plain text mode 

    I hope this further explains what am I trying to achieve and where is the problem.
    Thank you.

    Regards,
    MadBear

Similar Threads

  1. QGraphicsItem scale problem
    By qlands in forum Qt Programming
    Replies: 5
    Last Post: 9th June 2010, 16:43
  2. Why does QGraphicsItem::scenePos() return (0,0)
    By extrakun in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2009, 07:35
  3. QGraphicsItem meaning of pos(), scenePos()
    By nicolas1 in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2008, 08:59
  4. QGraphicsItem::scenePos() or pos()
    By Gopala Krishna in forum Newbie
    Replies: 3
    Last Post: 11th February 2007, 19:23
  5. Replies: 1
    Last Post: 26th September 2006, 05:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.