Results 1 to 4 of 4

Thread: Why does QGraphicsItem::scenePos() return (0,0)

  1. #1
    Join Date
    Jun 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Why does QGraphicsItem::scenePos() return (0,0)

    Hi all,

    I am trying to implement a drawing canvas with QGraphicsView and QGraphicsScene. What is perplexing is that after I add a new item to the scene, it's scenePos() is always (0,0). As a trial I test out the following code:

    Qt Code:
    1. QGraphicsLineItem * anotherLine = this->addLine(50,50, 100, 100);
    2. qDebug() << anotherLine->scenePos();
    3.  
    4. QGraphicsLineItem * anotherLine2 = this->addLine(80,10, 300, 300);
    5. qDebug() << anotherLine2->scenePos();
    To copy to clipboard, switch view to plain text mode 
    Where the this pointer is a class derived from QGraphicsScene. The output for both line is QPointF(0,0).

    To my understanding, scenePos() should be returning the position of the QGraphicsItem within the scene itself, but right now it is acting as if it is returning the origin of the item within its own local coordinate. What am I doing wrong?
    Last edited by extrakun; 20th July 2009 at 06:41. Reason: missing [code] tags

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why does QGraphicsItem::scenePos() return (0,0)

    and pos() value returns ..?
    Returns the position of the item in parent coordinates.
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Jun 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why does QGraphicsItem::scenePos() return (0,0)

    Quote Originally Posted by wagmare View Post
    and pos() value returns ..?
    Returns the position of the item in parent coordinates.
    It still returns QPointF(0,0)...

  4. #4
    Join Date
    Jun 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why does QGraphicsItem::scenePos() return (0,0)

    I realise my mistake. I should be doing this instead:

    Qt Code:
    1. // Length/angle of line
    2. QGraphicsLineItem * newLine = addLine(0,0, 100, 100);
    3.  
    4. // Move it to where i want it to be inside the scene
    5. newLine->setPos(50,50);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. error with QList with a class
    By john_god in forum Newbie
    Replies: 7
    Last Post: 12th January 2009, 21:48
  2. Once more : QAbstractItemModel woes
    By Valheru in forum Qt Programming
    Replies: 10
    Last Post: 15th January 2008, 10:44
  3. QTableView Repaint/Refresh
    By millsks in forum Newbie
    Replies: 9
    Last Post: 10th January 2008, 17:18
  4. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  5. Version 4.1.3 and QTreeView
    By greencastor in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 10:37

Tags for this Thread

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.