PDA

View Full Version : QGraphicsTextItem not remembering it's position



grabalon
2nd July 2010, 01:28
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?

grabalon
2nd July 2010, 02:06
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.

grabalon
6th July 2010, 16:55
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.