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. QMousePressEvent on QGraphicsView
Qt 6.11 is out! See what's new in the release blog

QMousePressEvent on QGraphicsView

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.9k Views 2 Watching
  • 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.
  • L Offline
    L Offline
    lenina15i25
    wrote on last edited by
    #1

    Good evening. Help to intercept the mouse click on QGraphicsView (which includes QGraphicsScene).
    There is a function: void mousePressEvent (QMouseEvent * mouseEvent) override.
    It intercepts the mouse event, but it does not intercept if the event occurs in QGraphicsView.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If you want to get the event that are happening in the scene, you need to subclass QGraphicsScene and reimplement QGraphicsScene::mousePressEvent.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

        If you want to get the event that are happening in the scene, you need to subclass QGraphicsScene and reimplement QGraphicsScene::mousePressEvent.

        L Offline
        L Offline
        lenina15i25
        wrote on last edited by
        #3

        @SGaist Thanks, I'll try to do.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          When learning how the coordinates works i used this

          class CustomScene : public QGraphicsScene {
          protected:
            void mousePressEvent(QGraphicsSceneMouseEvent* event) {
              QGraphicsScene::mousePressEvent(event);
              qDebug() << event->scenePos();
            }
          };
          
          

          Not sure what you are looking for but this is minimal sample of getting clicks.

          1 Reply Last reply
          1

          • Login

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