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: What is this velocity-dependent paint residue called and how do you get rid of it?
Forum Updated to NodeBB v4.3 + New Features

QGraphicsScene: What is this velocity-dependent paint residue called and how do you get rid of it?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 150 Views
  • 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.
  • enjoysmathE Offline
    enjoysmathE Offline
    enjoysmath
    wrote on last edited by aha_1980
    #1

    329a51bb-f210-49a9-9c80-f00ec7aa7134-image.png

    Anyone who's worked with custom QGraphicsItems has come across this rsidue that occurs. My analysis of it is that the new bounding rect doesn't cover the old one completely, and update() only updates the new rect region.

    So I could just change the update method to update the whole scene, but I want things to be as fast as possible, since I'll be bogging things down a lot with nested nodes, arrows and general scene complexity.

    So is there a way to fix this properly?

    Or is the only way to measure the velocity of mouse move and update accordingly on a region proportional to the velocity?

    This might be happening only because I have nodes within nodes, but I'm not sure.

    https://github.com/enjoysmath
    https://math.stackexchange.com/users/26327/exercisingmathematician

    1 Reply Last reply
    0
    • enjoysmathE Offline
      enjoysmathE Offline
      enjoysmath
      wrote on last edited by
      #2

      I do this in the method that captures the movement events of nested items:

      bool Node::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
      {
          auto item = static_cast<Item*>(watched);
      
          if (event->type() == QEvent::GraphicsSceneMouseMove && !item->detachedFromParentRect())
          {
              // Update a parent when any nested items move (for instance change bounding rect)
              // Only do this if the nested child is detached from its parent's rect
              // For instance, a label above a node that does not change the node's shape when
              // moved around is accomplished by setting detached flag to true.
              update();
      
              auto s = scene();
      
              if (s != nullptr) {
                  s->update();
              }
          }
      
          return Item::sceneEventFilter(watched, event);
      }
      

      And it works. Good enough for my purps!

      https://github.com/enjoysmath
      https://math.stackexchange.com/users/26327/exercisingmathematician

      1 Reply Last reply
      1

      • Login

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