QGraphicsScene - not updated after QGraphicsItem moved
-
I have such situation. From QGraphicsItem::mouseMoveEvent method call QGraphicsScene::updateBarierMap. updateBarierMap method get positions of QGraphicsPolygonItem`s and generate grid map. But scene hold old position of items, not updated after item move. How to get updated values of items on scene after mouseMoveEvent or how to inform scene, that item position changed?
Project svn url : https://freeman.svn.sourceforge.net/svnroot/freeman/qt4/trunk/qt4_book/sedgvik/path_a
-
-
bq. Perhaps you can show us the relevant pieces of code, instead of just pointing up to your application source and asking us to debug your problem? While a link to the full sources can come in handy, IMHO it is not a good thing to start with (just) that. bq.
Andre, thanks for reply.
This is relevant code that does not work properly.
@
void Scene::updateBarierMap()
{
foreach (QGraphicsItem* graphicsItem, items()) {
Item* item = qgraphicsitem_cast<Item*> (graphicsItem);
if (item) {
QPolygonF polygon = item->polygon();// foreach polygon point construct line
for (int index = 0; index < polygon.size(); ++index) {
int prevIndex = index - 1;
if (prevIndex < 0)
prevIndex = polygon.size()-1;QLineF line (polygon[prevIndex], polygon[index]); qDebug() << "line " << line.p1() << line.p2();
}
}
}
}@And relevant code for Item class, that inherits from QGraphicsPolygonItem
@
void Item::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
{
QGraphicsItem::mouseMoveEvent(event);Scene* scene_ptr = qobject_cast<Scene*> (scene());
if (scene_ptr) {
scene_ptr->updateBarierMap();
}
}
@When i call scene_ptr->updateBarierMap(); scene doesn't update coordinates of Item. qDebug() return the same coordinates.
How get from Scene::updateBarierMap() updated item coordinates?
-
Try to "update the geometry":http://doc.qt.nokia.com/latest/qgraphicsitem.html#prepareGeometryChange
or you can set to scene this flag "QGraphicsScene::NoIndex":http://doc.qt.nokia.com/latest/qgraphicsscene.html#ItemIndexMethod-enum maybe this will be better for your dynamic scene.