Results 1 to 5 of 5

Thread: QGraphicsEllipseItem: ItemSendsScenePositionChanges move event?

  1. #1
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QGraphicsEllipseItem: ItemSendsScenePositionChanges move event?

    Hi,

    i have a 4 vertices:

    Qt Code:
    1. Vertex::Vertex(int x, int y) : QGraphicsEllipseItem(x-1,y-1,x+1,y+1)
    2. {
    3. QPen currentPen = pen();
    4. currentPen.setColor(Qt::blue);
    5. currentPen.setWidth(3);
    6. setPen(currentPen);
    7. setAcceptsHoverEvents( true );
    8. setFlag( QGraphicsItem::ItemIsMovable, true );
    9. setFlag( QGraphicsItem::ItemSendsScenePositionChanges, true );
    10. }
    To copy to clipboard, switch view to plain text mode 

    that describe a polygon (QGraphicsPathItem)
    they are added to a QGraphicsScene in a QGraphicsView.

    So far, everything's fine; i can move the the vertices around, hover effects and so on are working fine.

    But now, i want to adjust the polygon if a user changes a vertex.
    Is there any event the QGraphicsEllipseItem emits when moved?
    Or does the QGraphicsScene have an event to tell me it's content hast changed?

    i am looking for something like:

    Qt Code:
    1. connect(m_scene, SIGNAL(changed()),
    2. this, SLOT(updatePolygon()));
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. Vertex* vertex = new Vertex(event->x(), event->y());
    2. connect(vertex, SIGNAL(ItemPositionHasChanged()),
    3. this, SLOT(updatePolygon()));
    To copy to clipboard, switch view to plain text mode 

    but both didn't work
    Last edited by Lykurg; 24th September 2010 at 16:09. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsEllipseItem: ItemSendsScenePositionChanges move event?

    See QGraphicsItem::itemChange() with QGraphicsItem::ItemPositionChange. If you need signals to inform your scene or whatever inherit QObject. Also not the difference between [QTCLASS] and [CODE].

  3. #3
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsEllipseItem: ItemSendsScenePositionChanges move event?

    Quote Originally Posted by Lykurg View Post
    See QGraphicsItem::itemChange() with QGraphicsItem::ItemPositionChange. If you need signals to inform your scene or whatever inherit QObject. Also not the difference between [QTCLASS] and [CODE].
    Qt Code:
    1. QVariant Vertex::itemChange(GraphicsItemChange change, const QVariant &value)
    2. {
    3. cout << "test" << std::endl;
    4. return QGraphicsItem::itemChange(change, value);
    5. }
    To copy to clipboard, switch view to plain text mode 

    itemChange is only called when the vertex is created, not when i move it

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsEllipseItem: ItemSendsScenePositionChanges move event?

    Yeah, sometimes you have to read the documentation
    This notification is send if the ItemSendsGeometryChanges flag is enabled

  5. The following user says thank you to Lykurg for this useful post:

    harakiri (27th September 2010)

  6. #5
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsEllipseItem: ItemSendsScenePositionChanges move event?

    Quote Originally Posted by Lykurg View Post
    Yeah, sometimes you have to read the documentation
    i did that, but i switched
    Qt Code:
    1. setFlag( QGraphicsItem::ItemSendsScenePositionChanges, true );
    To copy to clipboard, switch view to plain text mode 

    for

    Qt Code:
    1. setFlag( QGraphicsItem::ItemSendsGeometryChanges, true );
    To copy to clipboard, switch view to plain text mode 

    now it's working. thanks

Similar Threads

  1. QAbstractItemView not calling mouse move event function
    By sagirahmed in forum Qt Programming
    Replies: 0
    Last Post: 5th July 2010, 10:26
  2. Problem in Move Move Event Handler.
    By redgoof in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2010, 11:45
  3. QGraphicsEllipseItem
    By navi1084 in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2009, 08:48
  4. mouse move event filtering in PyQt4
    By lucaf in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2009, 14:53
  5. Mouse Move Event
    By merry in forum Newbie
    Replies: 5
    Last Post: 3rd June 2007, 06:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.