Results 1 to 8 of 8

Thread: Adding QGraphicItems to QGraphicScene causes the previous QGraphicItem to move. Why??

  1. #1
    Join Date
    Oct 2009
    Posts
    66
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Adding QGraphicItems to QGraphicScene causes the previous QGraphicItem to move. Why??

    Hi,
    I am working with QGraphicView, QGraphicScene and QGraphicItem to draw various rectangles on the scene. But once i add the item to the scene, causes the previous QGraphicItem to move, which is not required. Can some one please help me with this as to how can i stop the movement of the existing Items in scene while adding the new item.

    regards,
    sudhish

  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: Adding QGraphicItems to QGraphicScene causes the previous QGraphicItem to move. W

    Can you provide a minimal example on how you add the items to the scene since I never have notized such a behavior.

  3. #3
    Join Date
    Oct 2009
    Posts
    66
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Adding QGraphicItems to QGraphicScene causes the previous QGraphicItem to move. W

    I am drawing the rectangle on the mouse release event using the following code, please let me know what im doing wrong
    Qt Code:
    1. void GraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
    2. {
    3. static int rectCount;
    4. if(!selectionArea().isEmpty())
    5. {
    6. if(rectCount<7)
    7. {
    8. GraphicsRectItem *item = new GraphicsRectItem(selectionArea().boundingRect());
    9. addItem(item);
    10. rectCount ++;
    11. }
    12. }
    13. QGraphicsScene::mouseReleaseEvent(mouseEvent);
    14. }
    To copy to clipboard, switch view to plain text mode 

    where the GraphicScene and GraphicsRectItem classes are derived from QT QGraphicScene and QGraphicsRectItem as
    Qt Code:
    1. class GraphicScene : public QGraphicsScene
    2. class GraphicsRectItem : public QGraphicsRectItem
    To copy to clipboard, switch view to plain text mode 

  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: Adding QGraphicItems to QGraphicScene causes the previous QGraphicItem to move. W

    You don't position the item so I guess you have centered your scene in the view? Is that right? If so, positioning the scene at top left will stop moving your existing items around.

  5. #5
    Join Date
    Oct 2009
    Posts
    66
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Adding QGraphicItems to QGraphicScene causes the previous QGraphicItem to move. W

    How can i position the item? As there is no function which allows me to add the GraphicItem at a position. My requirement is to draw various rectangles on the given scene. How can i achieve this??

    Can you please help me with the functions which can be used.


    regards,
    sudhish

  6. #6
    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: Adding QGraphicItems to QGraphicScene causes the previous QGraphicItem to move. W


  7. #7
    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: Adding QGraphicItems to QGraphicScene causes the previous QGraphicItem to move. W

    Quote Originally Posted by kapoorsudhish View Post
    Hi,
    I am working with QGraphicView, QGraphicScene and QGraphicItem to draw various rectangles on the scene. But once i add the item to the scene, causes the previous QGraphicItem to move, which is not required. Can some one please help me with this as to how can i stop the movement of the existing Items in scene while adding the new item.
    Set a fixed size to the scene. If you forget to do it, the scene will expand to hold all items you place in it. If you add a new item, the scene expands and as the scene is centred in the view, other items will seem to "move" (in fact they won't, the scene will move in the view). See QGraphicsScene::setSceneRect()
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Oct 2009
    Posts
    66
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Adding QGraphicItems to QGraphicScene causes the previous QGraphicItem to move. W

    Hey Thanks wysota,


    The selection rectangles does not "move" after setting the graphic view Scene size.
    QGraphicsScene::setSceneRect()

    Thanks for the help Lykurg.

    regards,
    sudhish

Similar Threads

  1. QGraphicScene and different topmost QGraphicItem
    By Xaar in forum Qt Programming
    Replies: 3
    Last Post: 5th December 2007, 16:58
  2. identify QGraphicItem
    By avis_phoenix in forum Qt Programming
    Replies: 5
    Last Post: 24th September 2007, 06:16
  3. Location of QGraphicItem!!
    By rachana in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2007, 21:20
  4. need help with QGraphicItem
    By rachana in forum Qt Programming
    Replies: 13
    Last Post: 30th January 2007, 06:27
  5. Moving multiple QGraphicItems
    By StefanHirche in forum Newbie
    Replies: 2
    Last Post: 11th January 2007, 21:27

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.