Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9242087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:30:29+00:00 2026-06-18T08:30:29+00:00

I can’t find the way to attach mouse events to scene. Without View all

  • 0

I can’t find the way to attach mouse events to scene. Without View all events are capcured, but when commented out, only mousePressEvent works. Please, help.

from PySide import QtGui, QtCore

class Window(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.Scene()
        self.View()

    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            print "Pressed!!!"

    def mouseMoveEvent(self, event):
        print "moving....."

    def mouseReleaseEvent(self, event):
        print "-------released"

    def Scene(self):
        self.s = QtGui.QGraphicsScene(self)

    def View(self):
        self.v = QtGui.QGraphicsView(self.s)
        self.setCentralWidget(self.v)

if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.resize(300, 200)
    window.show()
    sys.exit(app.exec_())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:30:31+00:00Added an answer on June 18, 2026 at 8:30 am

    In Qt, events are handled from child to parent. First the child gets the event. Then it decides whether or not it’ll handle the event. If it doesn’t want to act on it, it can ignore the event and the event will be passed to the parent.

    In your setup, you have QMainWindow as the parent, and a QGraphicsView as its child. Every event on the QGraphicsView will be handled by the QGraphicsView first. If it doesn’t want the event, it will ignore it and pass on to the QMainWindow.

    To visualize it better, subclass QGraphicsView and override its mouse*Events:

    from PySide import QtGui, QtCore
    
    class View(QtGui.QGraphicsView):
        def mousePressEvent(self, event):
            print "QGraphicsView mousePress"
    
        def mouseMoveEvent(self, event):
            print "QGraphicsView mouseMove"
    
        def mouseReleaseEvent(self, event):
            print "QGraphicsView mouseRelease"
    
    class Window(QtGui.QMainWindow):
        def __init__(self):
            QtGui.QMainWindow.__init__(self)
            self.Scene()
            self.View()
    
        def mousePressEvent(self, event):
            print "QMainWindow mousePress"
    
        def mouseMoveEvent(self, event):
            print "QMainWindow mouseMove"
    
        def mouseReleaseEvent(self, event):
            print "QMainWindow mouseRelease"
    
        def Scene(self):
            self.s = QtGui.QGraphicsScene(self)
    
        def View(self):
            self.v = View(self.s)
            self.setCentralWidget(self.v)
    
    if __name__ == '__main__':
        import sys
        app = QtGui.QApplication(sys.argv)
        window = Window()
        window.resize(300, 200)
        window.show()
        sys.exit(app.exec_())
    

    And you’ll see an output like:

    QGraphicsView mousePress
    QGraphicsView mouseMove
    ...
    QGraphicsView mouseMove
    QGraphicsView mouseRelease
    

    As you can see, only the view gets to ‘see’ the events, because view doesn’t choose to pass the events.

    Alternatively, you can choose to ignore those events in the QGraphicsView. It’s like saying ‘I don’t do anything with this, let someone else take care of it’. And the event will be passed to the parent for it to choose what to do:

    class View(QtGui.QGraphicsView):
        def mousePressEvent(self, event):
            print "QGraphicsView mousePress"
            # ignore the event to pass on the parent.
            event.ignore()
    
        def mouseMoveEvent(self, event):
            print "QGraphicsView mouseMove"
            event.ignore()
    
        def mouseReleaseEvent(self, event):
            print "QGraphicsView mouseRelease"
            event.ignore()
    

    And the output:

    QGraphicsView mousePress
    QMainWindow mousePress
    QGraphicsView mouseMove
    QMainWindow mouseMove
    ...
    QGraphicsView mouseMove
    QMainWindow mouseMove
    QGraphicsView mouseRelease
    QMainWindow mouseRelease
    

    Now, you can see that view gets the event first. But since it ignores the event, it’s passed to the main window and only after that QMainWindow receives the signal.

    Long story short, don’t worry. Your view will receive events and act on them just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me trying to find out why this doesn't work. The brushes
Can anyone enlighten me to a way I can Highlight the content of an
Can someone please help me find the memory leak which is occurring here? I
Can any one provide me regex for finding all src tag. I am stuck
Can we use javap in our own java code in a programmable way? for
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can not find scala.actors package in latest milestones, while it still presents in scaladocs:
Can find why i get this error can someone help? package Android.data; public class
Let's say I'm outputting a post title and in our database, it's Hello Y’all
Can someone please tell me is there a way to solve difference equation e.g:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.