esotery
26th November 2012, 23:32
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:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QGraphicsScene* scene = new QGraphicsScene(this);
QGraphicsView* view = new QGraphicsView(this);
view->setScene(scene);
view->setMinimumSize(400, 200);
QGraphicsRectItem* item1 = new QGraphicsRectItem(0, 0, 50, 50);
item1->setFlag(QGraphicsItem::ItemIsMovable, true);
item1->setFlag(QGraphicsItem::ItemIsSelectable, true);
QGraphicsRectItem* item2 = new QGraphicsRectItem(0, 0, 50, 50);
item2->setFlags(item1->flags());
scene->addItem(item1);
scene->addItem(item2);
setCentralWidget(view);
}
I know it must be something stupid that I've overlooked.
Thank you for your help.
Small compilable example attached.
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:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QGraphicsScene* scene = new QGraphicsScene(this);
QGraphicsView* view = new QGraphicsView(this);
view->setScene(scene);
view->setMinimumSize(400, 200);
QGraphicsRectItem* item1 = new QGraphicsRectItem(0, 0, 50, 50);
item1->setFlag(QGraphicsItem::ItemIsMovable, true);
item1->setFlag(QGraphicsItem::ItemIsSelectable, true);
QGraphicsRectItem* item2 = new QGraphicsRectItem(0, 0, 50, 50);
item2->setFlags(item1->flags());
scene->addItem(item1);
scene->addItem(item2);
setCentralWidget(view);
}
I know it must be something stupid that I've overlooked.
Thank you for your help.
Small compilable example attached.