Results 1 to 2 of 2

Thread: QGraphicsItem::scenePos() not returning scene coordinates of item

  1. #1
    Join Date
    Jan 2006
    Location
    England
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile QGraphicsItem::scenePos() not returning scene coordinates of item

    OK, this only relates to Qt 4.2.

    Take this sample code:
    Qt Code:
    1. QGraphicsScene* scene = new QGraphicsScene(this);
    2.  
    3. scene->addEllipse(QRectF(110, 110, 20, 20)); // a circle with centre 120,120 and diameter 20
    4.  
    5. QGraphicsItem* item = sceneScene->itemAt(120, 120);
    6. cout << item->scenePos().x() << ", " << item->scenePos().y() << endl;
    To copy to clipboard, switch view to plain text mode 
    Now I would expect this to return the scene position of the object it found at, i.e. "120, 120" since QGraphicsItem::scenePos() just returns QGraphicsItem::mapToScene(0,0).

    However it only ever returns "0, 0".

    In fact
    Qt Code:
    1. cout << item->mapToScene(item->pos()).x() << ", " << item->mapToScene(item->pos()).x() << endl;
    2. cout << item->pos().x() << ", " << item->pos().y() << endl;
    To copy to clipboard, switch view to plain text mode 
    also all return "0, 0" whereas you would expect at least one of them to return something else.

    Is this a feature or a bug? Does anyone else have this problem or know why I am getting this result?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsItem::scenePos() not returning scene coordinates of item

    With which exact version of Qt 4.2 did you notice this? I tested with 4.2.0-rc1 and I noticed the same behaviour. I couldn't find anything related in the Task Tracker nor TT's mailing lists, though. Maybe try a recent snapshot of Qt 4.2 and inform the trolls if the problem still persists..?
    J-P Nurmi

Similar Threads

  1. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 01:34

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.