Observe this simple scene example which puts two buttons on the scene:
auto ww = new QGraphicsProxyWidget();
ww->setPos(900, 900);
auto ww2 = new QGraphicsProxyWidget();
ww2->setPos(500, 500);
scene->addItem(ww);
scene->addItem(ww2);
view->resize(1000, 1000);
view->setScene(scene);
view->show();
auto ww = new QGraphicsProxyWidget();
ww->setWidget(new QPushButton());
ww->setPos(900, 900);
auto ww2 = new QGraphicsProxyWidget();
ww2->setWidget(new QPushButton());
ww2->setPos(500, 500);
auto scene = new QGraphicsScene();
scene->addItem(ww);
scene->addItem(ww2);
auto view = new QGraphicsView();
view->resize(1000, 1000);
view->setScene(scene);
view->show();
To copy to clipboard, switch view to plain text mode
Everything works fine, and the two buttons appear at the specified positions.
However, if we now add the itemismovable flag to them like so:
auto ww = new QGraphicsProxyWidget();
ww->setPos(900, 900);
auto ww2 = new QGraphicsProxyWidget();
ww2->setPos(500, 500);
...
auto ww = new QGraphicsProxyWidget();
ww->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
ww->setWidget(new QPushButton());
ww->setPos(900, 900);
auto ww2 = new QGraphicsProxyWidget();
ww2->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
ww2->setWidget(new QPushButton());
ww2->setPos(500, 500);
...
To copy to clipboard, switch view to plain text mode
the the initial position of the items breaks. They both put over each other at position (0,0). However, if I call ww->setPos(...) after the view is shown, then that works.
Any idea what might be causing this?
Environment:
Qt 5.7
VS2013U5
Windows7SP1
Bookmarks