Results 1 to 7 of 7

Thread: QGraphicsItem setpos()

  1. #1
    Join Date
    Jul 2009
    Posts
    20
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default QGraphicsItem setpos()

    Hi

    I am saving out the properties of a textitem that was created for an image and constructing the item while reloading the image.However i seem to be making some mistake with pos()
    Here is what i use:

    QDataStream out(&itemfile);
    ....
    .....
    out<<textItem->pos();


    While reading in ,

    QPoint p;
    in >> p;
    textItem->setPos(p);

    this does not work .If i try to test using setPos(100,100), then the item is displayed.
    Apparently am making some mistake..

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem setpos()

    What does this return?
    Qt Code:
    1. qDebug() << p;
    To copy to clipboard, switch view to plain text mode 
    Are you sure you're in sync with the stream? Maybe you forgot to write or read something and the contents of the stream is different than you expect?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2009
    Posts
    20
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItem setpos()

    Hi

    While saving out the position, i use

    Qt Code:
    1. out<<(qint32(textItem->pos().x()));
    2. out<<(qint32(textItem->pos().y()));
    3. qDebug() << (qint32(textItem->pos().x()));
    4. qDebug() << (qint32(textItem->pos().y()));
    To copy to clipboard, switch view to plain text mode 

    qDebug() returns the following values:
    -----------------------------------------------------
    478
    46
    276
    366

    While reading in,

    Qt Code:
    1. qint32 px;
    2. qint32 py;
    3.  
    4. in >> px;
    5. in >> py;
    6. qDebug() << px;
    7. qDebug() << py;
    8. .....
    9. textItem->pos().setX(px);
    10. textItem->pos().setY(py);
    To copy to clipboard, switch view to plain text mode 

    qDebug() returns the following erroneous values:
    1075786547
    858993459
    0
    0

    I checked the sequence, am writing out and reading in proper order.Is my syntax for setting the coordinates correct ? What am i missing ?

    Thank you
    Last edited by wysota; 29th July 2009 at 07:40. Reason: missing [code] tags

  4. #4
    Join Date
    Jul 2009
    Posts
    20
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItem setpos()

    I am able to read back other attributes like text,font etc.So the issue is related only to position.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem setpos()

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default Re: QGraphicsItem setpos()

    Try to save
    While Writing:
    Qt Code:
    1. p=TextItem->pos();
    2. out<<p;
    To copy to clipboard, switch view to plain text mode 
    While Reading:
    Qt Code:
    1. in>>p;
    2. TextItem->setPos(p);
    To copy to clipboard, switch view to plain text mode 

    I have done like this and I got.
    One more thing if there are many No. of Items Whose position is to be saved better go for
    Qt Code:
    1. QList<QPointF *>
    To copy to clipboard, switch view to plain text mode 
    and save the QList.

  7. #7
    Join Date
    Jul 2009
    Posts
    20
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItem setpos()

    Thank you .That helped.

Similar Threads

  1. Replies: 2
    Last Post: 25th March 2011, 09:18
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. QGraphicsItem pos() and setpos()
    By jimc1200 in forum Qt Programming
    Replies: 6
    Last Post: 16th March 2009, 18:51
  4. Replies: 1
    Last Post: 25th February 2009, 00:34
  5. QGraphicsItem meaning of pos(), scenePos()
    By nicolas1 in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2008, 08:59

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.