How to get mouse press event on a QPixmap

  • I have a QPixmap that I add to a QGraphicsScene, which gives me a QGraphicsPixmapItem.
    How to get a mousePress event on the QGraphicsPixmapItem ?
    Tried to subclass the QGraphicsPixmapItem, but this gives me nothing.


  • Qt Champions 2017


    This sample works for me
    (i can click it )

    #include <QApplication>
    class myGraphicsPixmapItem: public QGraphicsPixmapItem {
      myGraphicsPixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
      ~myGraphicsPixmapItem() {
      void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) {
        QMessageBox::information(NULL, "Information!", "Mouse release Detected!");
    int main(int argc, char* argv[]) {
      QApplication app(argc, argv);
      QGraphicsScene scene;
      QPixmap pix(200, 200);
      QPainter* paint = new QPainter(&pix);
      paint->setPen(QColor(255, 34, 255, 255));
      paint->drawRect(0, 0, 200, 200);
      myGraphicsPixmapItem* pixmapItem = new myGraphicsPixmapItem(pix);
      delete paint;
      QGraphicsView view(&scene);
      return app.exec();

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.