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?
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?