Solved QGraphicsScene: What is this velocity-dependent paint residue called and how do you get rid of it?
-
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.
-
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!