Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsLineItem, mouseMoveEvent and updating P1 & P2
Forum Updated to NodeBB v4.3 + New Features

QGraphicsLineItem, mouseMoveEvent and updating P1 & P2

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jh224
    wrote on last edited by
    #1

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

    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jh224
        wrote on last edited by
        #3

        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)
        @

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

          [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

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jh224
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cincirin
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved