konvex
14th December 2008, 12:24
Hi, I can draw a line between two points and if the point moves the line moves too.
But now I would like to draw a second line between the first point and another one. This works, but then the line isn't connected to the points.
I don't know what's wrong, can somebody help me?
void GraphicsScene::mousePressEvent(QGraphicsSceneMouse Event *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);
}
}
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);
}
else
{ QGraphicsScene::mousePressEvent(e); }
}
}
void GraphicsScene::mouseMoveEvent(QGraphicsSceneMouseE vent *e)
{
if((e->buttons()==Qt::LeftButton) || (e->buttons()==Qt::RightButton))
{item2->setPos(e->scenePos());
item2->update();
linie->updatePosition();
linie->update();
}
QGraphicsScene::mouseMoveEvent(e);
}
But now I would like to draw a second line between the first point and another one. This works, but then the line isn't connected to the points.
I don't know what's wrong, can somebody help me?
void GraphicsScene::mousePressEvent(QGraphicsSceneMouse Event *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);
}
}
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);
}
else
{ QGraphicsScene::mousePressEvent(e); }
}
}
void GraphicsScene::mouseMoveEvent(QGraphicsSceneMouseE vent *e)
{
if((e->buttons()==Qt::LeftButton) || (e->buttons()==Qt::RightButton))
{item2->setPos(e->scenePos());
item2->update();
linie->updatePosition();
linie->update();
}
QGraphicsScene::mouseMoveEvent(e);
}