I have been creating an QT application but struck in a place. I have created own custom scene class deriving from QGraphicsScene from where I add my items like car,bus etc to the screen .
void Scene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (mouseEvent->button() != Qt::LeftButton)
return;
DiagramItem *item;
switch (myMode) {
case InsertItem:
item = new DiagramItem(myItemType, myItemMenu);
addItem(item);
item->setPos(mouseEvent->scenePos());
emit itemInserted(item);
break;
As you can see from the above code I have a DiagramItem class which is derived from QGraphicsPixmapItem for adding different item to scene.
switch (myDiagramType) {
case Bus:
setPixmap( QPixmap( Dir+"/images/bus1.jpg" ));
break;
case Car:
setPixmap( QPixmap( Dir+"/images/car4scene.png" ));
break;
case Truck:
What I want to achieve here is,When I select my item from the scene (car or bus ), I want to know which vehicle has been selected either car or bus or truck . I have no clue how to go on this . Can any one help me . I get the selected item like this from scene .
void MainWindow::itemSelected(QGraphicsItem *item) // signal sent from scene. {
DiagramItem *ItemSelect = qgraphicsitem_cast<DiagramItem *>(item);
// like to know 'ItemSelect' is car or bus or anyother vehicle
}