QGraphicsLineItem, mouseMoveEvent and updating P1 & P2
-
I'm having a problem moving a QGraphicsLineItem and P1 &P2 updating. I've got setMouseTracking set and itemIsMovable set. The item moves but P1 and P2 never gets updated. Any Suggestions?
@
myLineItem::myLineItem( QGraphicsItem *parent)
: QGraphicsLineItem(parent)
{
setFlag(QGraphicsItem::ItemIsMovable);
setFlag(QGraphicsItem::ItemIsSelectable);
}void myLineItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ // myLineItem moves as expected.....but p1 and p2 always stay the same
qDebug()<<" line p1 = "<<line().p1()<<" p2 = "<<line().p2();
QGraphicsItem::mouseMoveEvent(event);
}@
-
Cincirin,
Thank you for you're reply. Shouldn't P1 and P2 change with respect to the parent? In my case, P1 and P2 don't change at all. Is there some way to elegantly update these points?@
output from the move event:line p1 = QPointF(100, 200) p2 = QPointF(100, 400)
line p1 = QPointF(100, 200) p2 = QPointF(100, 400)
line p1 = QPointF(100, 200) p2 = QPointF(100, 400)
line p1 = QPointF(100, 200) p2 = QPointF(100, 400)
line p1 = QPointF(100, 200) p2 = QPointF(100, 400)
@ -
[quote author="jh224" date="1383564109"]Shouldn't P1 and P2 change with respect to the parent? [/quote]
No, P1 and P2 are in local coordinates, no parent coordinates. You are changing only item position relative to parent
[quote author="jh224" date="1383564109"]Is there some way to elegantly update these points?
[/quote]I don't know why you need parent coordinates, but these are mapping functions:
"QGraphicsItem::mapToParen":http://qt-project.org/doc/qt-5.0/qtwidgets/qgraphicsitem.html#mapToParent
and
"QGraphicsItem::mapToScene":http://qt-project.org/doc/qt-5.0/qtwidgets/qgraphicsitem.html#mapToScene