Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get mouse press event on a QPixmap
QtWS25 Last Chance

How to get mouse press event on a QPixmap

Scheduled Pinned Locked Moved Unsolved General and Desktop
mousepresseventqpixmapqgraphicspixmap
2 Posts 2 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EarthHobbit
    wrote on 19 Nov 2015, 18:51 last edited by
    #1

    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.

    Thanks.

    M 1 Reply Last reply 19 Nov 2015, 19:19
    0
    • E EarthHobbit
      19 Nov 2015, 18:51

      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.

      Thanks.

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 19 Nov 2015, 19:19 last edited by mrjj
      #2

      @EarthHobbit
      Hi

      This sample works for me
      (i can click it )

      #include <QApplication>
      #include<QGraphicsScene>
      #include<QGraphicsDropShadowEffect>
      #include<QGraphicsPixmapItem>
      #include<QMessageBox>
      #include<QGraphicsView>
      
      class myGraphicsPixmapItem: public QGraphicsPixmapItem {
       public:
        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);
        pixmapItem->setFlags(QGraphicsItem::ItemIsMovable);
        delete paint;
        QGraphicsView view(&scene);
        scene.addItem(pixmapItem);
        view.showFullScreen();
        return app.exec();
      }
      
      1 Reply Last reply
      1

      2/2

      19 Nov 2015, 19:19

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved