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);
    }

    @



  • All graphics item geometries are based on local item coordinates. Instead item position is based on parent coordinates. So when you move the item you change the position relative to parent, but not change their geometry



  • 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



  • Thanks for the explanation. By the way, I like your icon. PaulAner is one of my favorite beers.



  • [quote author="jh224" date="1383568597"]PaulAner is one of my favorite beers.[/quote]
    :-) for me all beers are favorites


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.