Results 1 to 3 of 3

Thread: QGraphicsItem::pos () different from mapToParent(0, 0)

  1. #1
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsItem::pos () different from mapToParent(0, 0)

    Hi, I have a problem with QGraphicsItem:os (), or just I don't get it.

    From the doc of QGraphicsItem:os (): "[...] this function returns the same as mapToParent(0, 0) [...]
    That is true except when applying a transformation to the item that is not centered on it's origin; e.g.:

    QTransform t;
    t.translate(c.x(), c.y());
    t.rotate(a);
    t.translate(-c.x(), -c.y());
    item->setTransform(t,true);

    where a is an angle and c (in item's local coordinates) is a point different from (0,0).
    For example:

    transform(): QTransform(type=TxShear, 11=0.983923 12=0.178594 13=0 21=-0.178594 22=0.983923 23=0 31=13.7529 32=-52.7745 33=1)

    pos(): QPointF(33, -246)
    mapToParent(0,0): QPointF(46.7529, -298.774)
    mapFromParent(pos()) : QPointF(-4.10658, 54.3822)


    when I expect:

    pos() == mapToParent(0,0)
    (0,0) == mapFromParent(pos())


    Any suggestions?
    Thanks

  2. #2
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItem::pos () different from mapToParent(0, 0)

    Hi,

    the problem seems to be related to the translation, nobody has encountered it?

    I believe I making something wrong, but also having QGraphicsItem::pos() != QGraphicsItem::mapToParent(0,0) seems quite strange to me, also because QGraphicsItem::scenePos() gives the correct value.

    I had a look at the source code and I see that pos() is maintained in a member d_ptr->pos, while scenePos() is defined as mapToScene(0, 0); so is that possible that d_ptr->pos is not updated when setting a translation()?

    Am I wrong?

    Thanks

    Hi again,
    this is an example (from examples\graphicsview\diagramscene):

    item = new DiagramItem(...);
    item->setPos(0,0);
    item->setTransform(QTransform().translate(50,100));

    output:

    item->pos(): QPointF(0, 0)
    item->mapFromParent(item->pos()): QPointF(-50, -100)
    item->mapToParent(0,0): QPointF(50, 100)
    item->mapFromParent(item->mapToParent(0,0)): QPointF(0, 0)

    item->scenePos(): QPointF(50, 100)
    item->mapFromScene(item->scenePos()): QPointF(0, 0)
    item->mapToScene(0,0): QPointF(50, 100)
    item->mapFromScene(item->mapToScene(0,0)): QPointF(0, 0)

    item->transform(): QTransform(type=TxTranslate, 11=1 12=0 13=0 21=0 22=1 23=0 31=50 32=100 33=1)


    Thanks
    Last edited by jado; 19th January 2012 at 18:14.

  3. #3
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItem::pos () different from mapToParent(0, 0)

    Hi,

    simply setTransform(.) doesn't affect pos() ?

    Thanks

Similar Threads

  1. Replies: 7
    Last Post: 29th November 2010, 19:20
  2. Problem with FBO in QGraphicsItem
    By Student3000 in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2010, 09:35
  3. QGraphicsItem not repainting
    By eijnuhs in forum Qt Programming
    Replies: 3
    Last Post: 20th September 2008, 08:54
  4. Casting QGraphicsItem child from QGraphicsItem
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 29th August 2008, 15:37
  5. Replies: 2
    Last Post: 28th June 2008, 16:31

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.