[Qt-interest] Lag of events and improper handling of mouse release when using QGraphicsItem::ItemIsMovable
Giancarlo Formicuccia
giancarlo.formicuccia at gmail.com
Sat Oct 29 18:53:49 CEST 2011
Hello,
In data sabato 29 ottobre 2011 12:32:01, Sherif Ghali ha scritto:
> There sometimes seems to be issues with QGraphicsScene efficiency even
> when the scene is trivial. The triangle in the following program is
> controlled by its nodes. While dragging one node there is a visible
> lag between the triangle edges and the node. The lag is disconcerting
> since the code does essentially nothing yet.
>
> Another problem is visible if you drag quickly then release the mouse.
> The dragged node will no longer coincide with a triangle vertex.
You should intercept ItemPositionHasChanged (instead of ItemPositionChange),
because it happens *after* the item position has actually changed.
If you use ItemPositionChange, the pos() method returns the previous object
position, and you'll end up connecting the lines to an outdated point.
This modified function works around the problem:
void control_point_has_moved(QGraphicsEllipseItem *node = 0,
const QPointF &pos = QPointF())
{
if (node==ez0) {
z01->setLine(QLineF(pos, ez1->pos()));
z20->setLine(QLineF(ez2->pos(), pos));
} else if (node==ez1) {
z01->setLine(QLineF(ez0->pos(), pos));
z12->setLine(QLineF(pos, ez2->pos()));
} else if (node==ez2) {
z12->setLine(QLineF(ez1->pos(), pos));
z20->setLine(QLineF(pos, ez0->pos()));
} else {
z01->setLine(QLineF(ez0->pos(), ez1->pos()));
z12->setLine(QLineF(ez1->pos(), ez2->pos()));
z20->setLine(QLineF(ez2->pos(), ez0->pos()));
}
update();
}
if called from Node::itemChanged with
dynamic_cast<MyGraphicsScene *>(scene())->control_point_has_moved(
this, newPos);
but I think the correct solution is to use ItemPositionHasChanged.
Giancarlo
More information about the Qt-interest-old
mailing list