PDA

View Full Version : QGraphicsRectItem subclass and mouseMoveEvent



almo
16th May 2012, 22:37
Hi!

I have a subclass of QGraphicsRectItem. The mouseMoveEvent handler looks like this:


void BTNodeGraphicsItem::mouseMoveEvent(QGraphicsSceneM ouseEvent* event)
{
QGraphicsRectItem::mouseMoveEvent(event);
qDebug() << rect().x() << " " << rect().y();
}

The item drags like I expect. But the qDebug statement outputs the same coordinates as I drag it. Shouldn't the rect be changing as it is dragged?

almo
17th May 2012, 14:50
OK, thanks again for looking! Here's what it turned out to be after quite a bit of messing around:


QPointF newCenter(mapToScene(rect().center().x(), rect().center().y()));
qDebug() << newCenter.x() << " " << newCenter.y();