Results 1 to 5 of 5

Thread: New position not updated to the parent in QtGraphicsScene

  1. #1
    Join Date
    Apr 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default New position not updated to the parent in QtGraphicsScene

    Hello,

    I'm new in Qt and working on a project that uses QtGraphicsScene. I'm using Qt4.6.

    I create a new QGraphicsRectItem with a QGraphicsItem as it parent.
    When I then move the QGraphicsRectItem with moveBy or setRotation the parent still gets the old position of the QGraphicsRectItem. I've set the mouse to change shape when I hover over QGraphicsRectItem and it changes shape on the new and on the old position. When I ignore a mouse event in QGraphicsRectItem on the new position the parent does not get the mouse event. The parent but still receives events when i click on the old position.
    I've enabled the ItemIsMovable, ItemIsSelectable, ItemSendsGeometryChanges, ItemSendsScenePositionChanges flags.
    Is there something else i should do?

    Thanks in advance.

    Marnix

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: New position not updated to the parent in QtGraphicsScene

    Can we see some code? Did you reimplement any of the methods from QGraphicsRectItem?

  3. #3
    Join Date
    Apr 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: New position not updated to the parent in QtGraphicsScene

    Hello,

    I partially solved my problem. I had reimplemented the shape function for QGraphicsRectItem (I only want the border and not filled) and QGraphicsScene. In QGraphicsScene I called the the reimplemented QGraphicsRectItem shape and did not translate this shape by the moved distance. So after the translation of the QPainterPath the parent gets the the mouse events. However I also need to rotate and there does not exist by my knowledge a function to rotate a QPainterPath. I'll think there should exit move and rotation (in local coordinates) that also adapt the shape so parents can access the shape of there children without the need for translation or rotation. I'll try to re implement everything with QTransform matrices.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: New position not updated to the parent in QtGraphicsScene

    I think you are approaching the problem from the wrong end. boundingRect() and shape() should return an invariant coordinates of the item. If a car is 3 metres long, if it turns right it is still 3 metres long. If you look at the car from a distance it will look like being shorter than 3 metres but in fact it will still be 3 metres long. If you move it to another parking lot it will retain its 3 metres length.

    You should be transforming the item - rotating, scaling, translating it but the item itself will still have the original size and shape, so boundingRect() and shape() should return constant values unless the actual shape (outline) of the item changes (i.e. if you open the doors in your 3 metres long car).

  5. #5
    Join Date
    Apr 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: New position not updated to the parent in QtGraphicsScene

    I use the mutiple objects for visualy measuring things on an underlying bitmap, so they realy schange shape. I solved with my problem with QTransform.map witch can rotate an QPainterPath.

Similar Threads

  1. Layout not updated when sizeHint changes
    By ArmanS in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2010, 14:31
  2. QTextEdit not being updated
    By doggrant in forum Qt Programming
    Replies: 3
    Last Post: 2nd September 2009, 17:25
  3. elements not updated
    By danesh in forum Qt Programming
    Replies: 2
    Last Post: 2nd April 2009, 08:35
  4. HaiQ updated for Qt 4.4
    By magland in forum Qt-based Software
    Replies: 8
    Last Post: 19th September 2008, 11:42
  5. QHash only getting updated not populated
    By quickNitin in forum Newbie
    Replies: 2
    Last Post: 13th July 2006, 11:32

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.