Mouse click events for QPixmapItem objects
-
Hi everyone,
I'm playing around with Qt to get a grip of its basics, and can't seem to do it very well.
Here's a few lines of my code:
@int main(int argc, char *argv[])
{
QApplication app(argc, argv);QGraphicsScene scene; QGraphicsView view(&scene); QGraphicsPixmapItem item(QPixmap("C:\\card set\\s8.gif")), item2(QPixmap("C:\\card set\\s9.gif")); scene.addItem(&item), scene.addItem(&item2); view.show(); return app.exec();
}@
How do I go about adding click events for these objects?
Is there a more efficient way to declare and add items?I checked the documentation, but it still seems a bit confusing.
I'd like to get quite a thorough explanation. Sorry if it seems noobish, but..I am very new to this.
Thank you!
-
You can subclass QGraphicsView, implement mousePressEvent and use itemAt() like shown in "this example":http://qt-project.org/doc/qt-5/qgraphicsview.html#itemAt
As for more info on how to use graphics view you can look at "these examples":http://qt-project.org/doc/qt-5/examples-graphicsview.html