Hi, I have an app with a QGraphicsScene and a button.

If the user clicks the button, and clicks later on the scene, a QGraphicsLine is created, the final point of the line "follows" the pointer and when the user clicks again the last point is settled. In a nutshell, the normal behavior in any vector graphics editor.

I first tried with this code:

Qt Code:
  1. QGraphicsLineItem* create(QPointF initPoint, QPointF finalPoint)
  2. {
  3. pLine->line().setPoints(pLine->initPoint, finalPoint);
  4. m_pScene->addItem(pLine );
  5. return pLine;
  6. }
To copy to clipboard, switch view to plain text mode 

The final point of the line is changed in its paint method.

BUT all the QGraphcsLineItem I created started in the same starting point (of course, "initPoint" was always different). And I'm 100% sure it wasn't changed at all in any part of my code.

So I tried this code:

Qt Code:
  1. QGraphicsLineItem* create(QPointF initPoint, QPointF finalPoint)
  2. {
  3. QLineF auxLine(initPoint, finalPoint);
  4. pLine->setLine(auxLine);
  5. m_pScene->addItem(pLine );
  6. return pLine;
  7. }
To copy to clipboard, switch view to plain text mode 


And it works!!!

I would like to ask you if you know what could have been going wrong with the first code... I tried few things, like setting it's post mapped from scene, and mapping different coords... but no success.

thanks!