저는 프로그래밍 초보자이며 도움이 필요합니다.기능 : QGraphicsScene에서 클릭 한 개체 얻기
Class Station {
int x
int y
...
}
모든 스테이션 동그라미와 텍스트로 QGraphicsScene
에 그리는 :
내가 X
및 Y
필드를 포함하는 클래스 Station
이,이
this->scene.addEllipse(x1, y1, diam, diam, pen, QBrush(...));
나는 기능을 필요 getClickedStation
, QGraphicsScene
을 클릭하기를 기다리고 서클을 찾고 좌표의 해당 역을 반환합니다 :
Station* getClickedStation(...) { ... }
어떤 방법이 있습니까?
난 그냥 좌표를 얻을이 시도했습니다 ... 그것으로
QList<QGraphicsItem*> listSelectedItems = scene.selectedItems();
QGraphicsItem* item = listSelectedItems.first();
ui->textBrowserMenu->append(QString::number(item->boundingRect().x()));
ui->textBrowserMenu->append(QString::number(item->boundingRect().y()));
하지만, 프로그램 충돌을
입니까? [Minimal, Complete, Verifiable example] (http://stackoverflow.com/help/mcve)를 게시하십시오. 또한, http://stackoverflow.com/tour – ericbn
편집 됨, 감사합니다. –