Next two methodes are the mouseEvents from my Graphics class (this is the class which is derived from QGraphicsItem). getStartPosition & getEndPosition are the 2 signals which are sent:
{
if (brushcolor == Qt::green)
brushcolor = Qt::black;
else
brushcolor= Qt::green;
update();
point = this->scenePos();
getStartPosition(point);
}
{
if (brushcolor == Qt::green)
brushcolor = Qt::black;
else
brushcolor= Qt::green;
update();
point = this->scenePos();
getEndPosition(point);
}
void Graphics::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (brushcolor == Qt::green)
brushcolor = Qt::black;
else
brushcolor= Qt::green;
update();
QPointF point;
point = this->scenePos();
getStartPosition(point);
QGraphicsItem::mousePressEvent(event);
}
void Graphics::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (brushcolor == Qt::green)
brushcolor = Qt::black;
else
brushcolor= Qt::green;
update();
QPointF point;
point = this->scenePos();
getEndPosition(point);
QGraphicsItem::mouseReleaseEvent(event);
}
To copy to clipboard, switch view to plain text mode
I've also added a picture, on which you can see that I've place 256 Items nicely on a graphicsScene. But when I click on one, and release on another, the same position is send
Bookmarks