Now I have done something like this, but it does not work.
graphicsscene.cpp
{
pos=e->scenePos();
if(e->button() == Qt::LeftButton)
{
if(itemAt(pos))
else
{
EllipseItem *item = new EllipseItem(pos.x()-5, pos.y()-5,10,10);
addItem(item);
}}}
void GraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
pos=e->scenePos();
if(e->button() == Qt::LeftButton)
{
if(itemAt(pos))
{ QGraphicsScene::mousePressEvent(e); }
else
{
EllipseItem *item = new EllipseItem(pos.x()-5, pos.y()-5,10,10);
item->setFlags(QGraphicsItem::ItemIsMovable);
addItem(item);
}}}
To copy to clipboard, switch view to plain text mode
ellipseitem.cpp
{
setRect((e->scenePos().x()-5),(e->scenePos().y()-5),10,10);
end = e->scenePos();
if(isSelected() && e->button() == Qt::RightButton)
{
LineItem *linie = new LineItem((e->scenePos().x()),(e->scenePos().y()),end.x(),end.y());
sc->addItem(linie);
}}
void EllipseItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
{
setRect((e->scenePos().x()-5),(e->scenePos().y()-5),10,10);
end = e->scenePos();
setFlag(QGraphicsItem::ItemIsSelectable, true);
if(isSelected() && e->button() == Qt::RightButton)
{
sc = new QGraphicsScene;
LineItem *linie = new LineItem((e->scenePos().x()),(e->scenePos().y()),end.x(),end.y());
sc->addItem(linie);
}}
To copy to clipboard, switch view to plain text mode
lineitem.cpp
{
startpkt = e->scenePos();
endpkt = e->scenePos();
setLine(startpkt.x(),startpkt.y(),endpkt.x(),endpkt.y());
}
void LineItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
{
startpkt = e->scenePos();
endpkt = e->scenePos();
setLine(startpkt.x(),startpkt.y(),endpkt.x(),endpkt.y());
}
To copy to clipboard, switch view to plain text mode
I draw two ellipse (this works) in the scene and if I choose one and move the mouse to the other the should appear the line(this don't work).
I don't know whats the problem...
Please help
Bookmarks