Results 1 to 3 of 3

Thread: QGraphicsTextItem not remembering it's position

  1. #1
    Join Date
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsTextItem not remembering it's position

    Hey,

    I have a strange issue in my application. Using the QGraphics tools (View, Scene, TextItem) I am trying to make a simple 'click here, put text into the scene, move it at will, then remove it' interface. Here's how I add my textItems:

    1: QGraphicsTextItem* textItem = new QGraphicsTextItem(Prompt::getResponse(), NULL);
    2: textItem->setFlags(QGraphicsTextItem::ItemIsSelectable | QGraphicsTextItem::ItemIsMovable);
    3: textItem->setFont(myFont);
    4: textItem->setZValue(1000.0);
    5: addItem(textItem);
    6: textItem->setDefaultTextColor(myTextColor);
    7: textItem->setPos(mouseEvent->scenePos());

    It all works fine except the 'move at will' portion. The behavior is that when you click and drag, the textItem will jump back to the position set in line 7 above before following the mouse movement. I am doing no handling of the mouse events as far as this item is concerned. Can someone tell me either why it would suddenly jump when you start a drag, or how to fix this?

  2. #2
    Join Date
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsTextItem not remembering it's position

    Correction on how it behaves:

    Sometimes it goes to the original location, and other times it goes to (0, 0)

    Any help would be appreciated.

  3. #3
    Join Date
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsTextItem not remembering it's position

    Alright, I've hunted down the behavior. The first text item I add saves it's original location and, when I try to move it, jumps to where it first was placed before letting me pan it around. The subsequent items I place forget even their original positions and jump to (0, 0). Panning still works, but I can't having text items suddenly jumping away from my mouse, especially if where they jump to is off the screen.

Similar Threads

  1. QGraphicsTextItem and text cursor position via QPoint
    By Lykurg in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2017, 18:38
  2. QGraphicsTextItem - setHTML()
    By Claymore in forum Qt Programming
    Replies: 7
    Last Post: 17th September 2009, 09:34
  3. Word at mouse click position in QGraphicsTextItem
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 04:56
  4. QGraphicsTextItem: handling cursor position change
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2007, 10:42
  5. QGraphicsTextItem - is it a bug there?
    By Tair in forum Qt Programming
    Replies: 5
    Last Post: 18th October 2006, 08:48

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.