Results 1 to 3 of 3

Thread: QGraphicsItem move influences other items in scene

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsItem move influences other items in scene

    Hello,

    I have come across some behaviour of Scene (or maybe Item) that I don't like and I don't know how to get rid of it.

    I have Scene with two items. They are both Movable and Selectable. They are stacked on each other and if I move the top Item to whatever direction, it will also move the other Item that is beneath it to opposite direction.

    The code is really simple:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent)
    3. {
    4. QGraphicsScene* scene = new QGraphicsScene(this);
    5. QGraphicsView* view = new QGraphicsView(this);
    6. view->setScene(scene);
    7. view->setMinimumSize(400, 200);
    8.  
    9. QGraphicsRectItem* item1 = new QGraphicsRectItem(0, 0, 50, 50);
    10. item1->setFlag(QGraphicsItem::ItemIsMovable, true);
    11. item1->setFlag(QGraphicsItem::ItemIsSelectable, true);
    12. QGraphicsRectItem* item2 = new QGraphicsRectItem(0, 0, 50, 50);
    13. item2->setFlags(item1->flags());
    14.  
    15. scene->addItem(item1);
    16. scene->addItem(item2);
    17.  
    18. setCentralWidget(view);
    19. }
    To copy to clipboard, switch view to plain text mode 

    I know it must be something stupid that I've overlooked.

    Thank you for your help.

    Small compilable example attached.
    Attached Files Attached Files

Similar Threads

  1. Problem with positioning a QGraphicsItem in the scene
    By qlands in forum Qt Programming
    Replies: 0
    Last Post: 1st October 2010, 11:05
  2. Overload QGraphicsItem Move in Scene
    By D Cell in forum Newbie
    Replies: 2
    Last Post: 16th March 2010, 05:14
  3. Can I copy a QGraphicsItem on my scene?
    By JesperWe in forum Qt Programming
    Replies: 3
    Last Post: 12th February 2010, 21:21
  4. add items into scene
    By Noxxik in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2009, 16:32
  5. Can't move Items in the scene
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2008, 09:40

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
  •  
Qt is a trademark of The Qt Company.