tuli
8th September 2016, 22:58
Observe this simple scene example which puts two buttons on the scene:
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();
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->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);
...
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
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();
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->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);
...
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