{
pos=e->scenePos();
end=e->scenePos();
item = new EllipseItem(pos.x(), pos.y(),10,10);
item2 = new EllipseItem(end.x(), end.y(),10,10);
if(e->button() == Qt::LeftButton)
{
if(itemAt(pos))
else
{
addItem(item);
linie = new LineItem(item,item2);
QObject::connect(item,
SIGNAL(positionchanged
()), linie ,
SLOT(updatePosition
()));
QObject::connect(item2,
SIGNAL(positionchanged
()), linie ,
SLOT(updatePosition
()));
addItem(linie);
//here I draw the item and a line, which is connected to the item and item2, this works
}
}
if(e->button() == Qt::RightButton)
{
if(itemAt(pos))
{
linie = new LineItem(item,item2);
QObject::connect(item,
SIGNAL(positionchanged
()), linie ,
SLOT(updatePosition
()));
QObject::connect(item2,
SIGNAL(positionchanged
()), linie ,
SLOT(updatePosition
()));
addItem(linie);
//here should appear the second line (without creating a new item(startpoint) and a new item2, which is connected, too.
//but when I move item or item2 , the line doesn't move
//this doesn't work
}
else
}
}
{
if((e->buttons()==Qt::LeftButton) || (e->buttons()==Qt::RightButton))
{item2->setPos(e->scenePos());
item2->update();
linie->updatePosition();
linie->update();
}
}
{
end=e->scenePos();
if(itemAt(end))
else
{addItem(item2);} //here I draw item2
}
void GraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
pos=e->scenePos();
end=e->scenePos();
item = new EllipseItem(pos.x(), pos.y(),10,10);
item2 = new EllipseItem(end.x(), end.y(),10,10);
item->setFlags(QGraphicsItem::ItemIsMovable);
item2->setFlags(QGraphicsItem::ItemIsMovable);
if(e->button() == Qt::LeftButton)
{
if(itemAt(pos))
{QGraphicsScene::mousePressEvent(e); }
else
{
addItem(item);
linie = new LineItem(item,item2);
QObject::connect(item, SIGNAL(positionchanged()), linie , SLOT(updatePosition()));
QObject::connect(item2, SIGNAL(positionchanged()), linie , SLOT(updatePosition()));
addItem(linie);
//here I draw the item and a line, which is connected to the item and item2, this works
}
}
if(e->button() == Qt::RightButton)
{
if(itemAt(pos))
{
linie = new LineItem(item,item2);
QObject::connect(item, SIGNAL(positionchanged()), linie , SLOT(updatePosition()));
QObject::connect(item2, SIGNAL(positionchanged()), linie , SLOT(updatePosition()));
addItem(linie);
//here should appear the second line (without creating a new item(startpoint) and a new item2, which is connected, too.
//but when I move item or item2 , the line doesn't move
//this doesn't work
}
else
{ QGraphicsScene::mousePressEvent(e); }
}
}
void GraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
{
if((e->buttons()==Qt::LeftButton) || (e->buttons()==Qt::RightButton))
{item2->setPos(e->scenePos());
item2->update();
linie->updatePosition();
linie->update();
}
QGraphicsScene::mouseMoveEvent(e);
}
void GraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
{
QGraphicsScene::mouseReleaseEvent(e);
end=e->scenePos();
if(itemAt(end))
{QGraphicsScene::mouseReleaseEvent(e);}
else
{addItem(item2);} //here I draw item2
}
To copy to clipboard, switch view to plain text mode
Do you know how I could connect the item to the line?
Bookmarks