2012-05-17 13 views
0

我有一個QGraphicsRectItem的子類。 mouseMoveEvent處理程序如下所示:如何在mouseMove中獲取QGraphicsRectItem的位置?

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

該項目拖動像我期望的一樣。但是,當我拖動它時,qDebug語句會輸出相同的座標。不應該因爲被拖動而改變?

回答

0

您正在獲取相對於圖形項目的座標中的位置。要從另一個角度獲取座標,請使用類似mapToScene(rect())

+0

這很有效,謝謝! – Almo