I'm making a QT application but hit it on one place. I have received my custom footage class from QGraphicsScene, from where I add my items like cars, buses etc to the screen.
View from zero: Mousepress Event (QGraphicsSceneMouseEvent * mouseEvent) {If (mouseEvent-> Button (!)! = Qt :: LeftButton) Return; Drawing item * items; Switch (mime) {insert case}: item = new diagram item (myItemType, myItemMenu); AddItem (item); Items, & gt; SetPos (mouseEvent-> scenePos ()); Empty item (item); break; As you can see from the code above, I have a diagram item class that has been taken from QGraphicsPixmapItem to add different items for the view.
switch (myDiagramType) {case bus: setpixmap (Dir + "/ images / bus1.jpg")); break; Case Car: Set Pixmap (Dir + "/ images / car4scene.png")); break; Case truck: What do I want to achieve here, when I choose from my item (car or bus), I want to know what car or bus either Or truck I have no clue how to go about it. Can somebody help me out . I get the selected object in this way from the scene.
The main menu :: item selected from zero (QGraphicsItem * item) // is sent from the signal view. {
Diagram Eatam * Candidate = qgraphicsitem_cast & lt; DiagramItem * & gt; (item); // Want to know 'item' selection is car or bus or some other vehicle
}
If the diaper element is from your own design, then keep only the type internally and provide a method to query it Alternatively, keep a hash where the key is DiagramItem * And value type.
Comments
Post a Comment