1
我有一個QGraphicsScene存儲QGraphicsLinesItems和QGraphicsRectItems。使用QGraphicsScene ItemAt()來檢測QGraphicsLineItem
我使用QGraphicsScene方法itemsAt()和我通過x和y座標ordiantes返回的QGraphicsItem我用的是以下幾點:
QPointF getItemPos= this->mapToScene(this->mapFromGlobal(QCursor::pos()));
QGraphicsItem *itm = scene->itemAt(getItemPos.x(),getItemPos.y());
QGraphicsLineItem *lineItm;
QGraphicsRectItem *rectItm;
if((lineItm = dynamic_cast<QGraphicsLineItem*>(itm))){
// do stuff with as_pnedge
qDebug("Line");
}else if((rectItm = dynamic_cast<QGraphicsRectItem*>(itm))){
// do stuff with as_pnitem
qDebug("Rect");
}
else
{
qDebug("Select Item");
}
我遇到的問題是返回QGraphicsRectItem罰款並且可以被檢測到。但無論我在哪裏點擊QGraphicsLineItems,它都無法檢測並返回該項目。任何援助將非常感激。