Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] Handle mouse press in a QGraphicsScene

    General and Desktop
    2
    3
    756
    Loading More Posts
    • 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.
    • A
      alanbortu last edited by

      Hello I am attempting to capture a mouse press in a QGraphicsScene. What I want to do is when a user presses the "Delete Room" button, the application goes into a mode so that when the mouse is clicked (for a second time after the button is pressed, think of it like a "select to delete") it just prints something to the debug.

      Here is a screenshot of the application http://paste.opensuse.org/view/raw/35139719

      I am pretty new to Qt so I am probably missing something here. My instinct was to use signals and slots to change the mode after a button press but I dont know how to capture the mouse within the QGraphicsScene (which is in a QGraphicsView).

      Thank you for any help you can give.

      1 Reply Last reply Reply Quote 0
      • Q
        qxoz last edited by

        You can inherit QGraphicsScene and reimplement mouse events.
        Take a look to "examples":https://qt-project.org/doc/qt-5/examples-graphicsview.html . There you will find many useful solutions.

        1 Reply Last reply Reply Quote 0
        • A
          alanbortu last edited by

          Thank you, I have it working now. For anyone who comes across it on google, I just reimplemented @void mousePressEvent(QGraphicsSceneMouseEvent *event);@

          1 Reply Last reply Reply Quote 0
          • First post
            Last post