Salut,
J'essais d'utiliser QGraphicsItem::pos() mais j'obtient toujours la position de l'item par rapport à la position où il a été crée.
Donc si l'item n'effectue aucun mouvement, on faisant item->pos() j'obtient toujours (0,0), de même si j'utilise item->scenePos()
Voici comment je crée mon item:
Merci.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 void EquipementLayoutView::dropEvent(QDropEvent *event) { QPointF pos = this->mapToScene(event->pos()); MinerGraphicsItem* Miner = new MinerGraphicsItem(); //hérite de QGraphicsRectItem Miner->setRect(pos.x(), pos.y(), 10, 10); Miner->setSelected(true); this->scene()->addItem(Miner); this->scene()->update(); qDebug() << Miner->pos(); // j'obtient (0,0) QGraphicsView::dropEvent(event); }
Partager