Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsScene - not updated after QGraphicsItem moved
Forum Updated to NodeBB v4.3 + New Features

QGraphicsScene - not updated after QGraphicsItem moved

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 5.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    feniksa
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        feniksa
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rokemoon
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved