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:
{
pLine->line().setPoints(pLine->initPoint, finalPoint);
m_pScene->addItem(pLine );
return pLine;
}
QGraphicsLineItem* create(QPointF initPoint, QPointF finalPoint)
{
QGraphicsLineItem* pLine = new QGraphicsLineItem();
pLine->line().setPoints(pLine->initPoint, finalPoint);
m_pScene->addItem(pLine );
return pLine;
}
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:
{
QLineF auxLine
(initPoint, finalPoint
);
pLine->setLine(auxLine);
m_pScene->addItem(pLine );
return pLine;
}
QGraphicsLineItem* create(QPointF initPoint, QPointF finalPoint)
{
QGraphicsLineItem* pLine = new QGraphicsLineItem();
QLineF auxLine(initPoint, finalPoint);
pLine->setLine(auxLine);
m_pScene->addItem(pLine );
return pLine;
}
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!
Bookmarks