PDA

View Full Version : What's the difference? (QLineF, pos, setPoints())



jano_alex_es
28th October 2009, 10:59
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:



QGraphicsLineItem* create(QPointF initPoint, QPointF finalPoint)
{
QGraphicsLineItem* pLine = new QGraphicsLineItem();
pLine->line().setPoints(pLine->initPoint, finalPoint);
m_pScene->addItem(pLine );
return pLine;
}


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:



QGraphicsLineItem* create(QPointF initPoint, QPointF finalPoint)
{
QGraphicsLineItem* pLine = new QGraphicsLineItem();
QLineF auxLine(initPoint, finalPoint);
pLine->setLine(auxLine);
m_pScene->addItem(pLine );
return pLine;
}



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!

Lykurg
28th October 2009, 11:52
QGraphicsLineItem::line() doesn't return a pointer/reference with which you could change the coordinates of the QGraphicsLineItem. It only returns a copy. So all changes you are made are lost.