Python - PyQT4 how to detect the mouse click position anywhere in the window?
Question: I have 1024x768 resolution window, when there is a click or mouse over, i want
to find the x, y values. How can i do that?

    
    
    import sys
    from PyQt4 import QtGui, QtCore
    
    
    class Example(QtGui.QWidget):
    
        def __init__(self):
            super(Example, self).__init__()
    
            self.initUI()
    
        def initUI(self):               
    
            qbtn = QtGui.QPushButton('Quit', self)
            #qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
            qbtn.clicked.connect(self.test)
            qbtn.resize(qbtn.sizeHint())
            qbtn.move(50, 50)       
    
            self.setGeometry(0, 0, 1024, 768)
            self.setWindowTitle('Quit button')    
            self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
            self.show()
    
        def test(self):
          print "show the position of mouse cursor in screen resolution: x is ?? , y is ??"
    
    def main():
    
        app = QtGui.QApplication(sys.argv)
        ex = Example()
        sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
        main()
    


Answer: 
    import sys
    from PyQt4 import QtGui, QtCore
    
    class Example(QtGui.QWidget):
    
        def __init__(self):
            super(Example, self).__init__()
    
            self.initUI()
    
        def mousePressEvent(self, QMouseEvent):
            print QMouseEvent.pos()
    
        def mouseReleaseEvent(self, QMouseEvent):
            cursor =QtGui.QCursor()
            print cursor.pos()        
    
        def initUI(self):               
    
            qbtn = QtGui.QPushButton('Quit', self)
            #qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
            #qbtn.clicked.connect(self.test)
            qbtn.resize(qbtn.sizeHint())
            qbtn.move(50, 50)       
    
            self.setGeometry(0, 0, 1024, 768)
            self.setWindowTitle('Quit button')    
            self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
            #self.connect("clicked", self.test)
            self.show()
        def test(self):
          print "test"
    
    def main():
    
        app = QtGui.QApplication(sys.argv)
        ex = Example()
        sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
        main()
    

Output:

    
    
    PyQt4.QtCore.QPoint(242, 285)
    PyQt4.QtCore.QPoint(1741, 423)
    PyQt4.QtCore.QPoint(439, 372)
    PyQt4.QtCore.QPoint(1509, 549)
    PyQt4.QtCore.QPoint(90, 6)
    PyQt4.QtCore.QPoint(1468, 50)
    PyQt4.QtCore.QPoint(302, 372)
    PyQt4.QtCore.QPoint(1674, 382)
    PyQt4.QtCore.QPoint(501, 416)
    PyQt4.QtCore.QPoint(1867, 416)
    PyQt4.QtCore.QPoint(605, 391)
    PyQt4.QtCore.QPoint(1971, 391)
    PyQt4.QtCore.QPoint(18, 16)
    PyQt4.QtCore.QPoint(1384, 16)
    PyQt4.QtCore.QPoint(12, 12)
    PyQt4.QtCore.QPoint(1378, 12)
    PyQt4.QtCore.QPoint(12, 12)
    PyQt4.QtCore.QPoint(1378, 12)
    PyQt4.QtCore.QPoint(12, 12)
    PyQt4.QtCore.QPoint(1378, 12)
    PyQt4.QtCore.QPoint(1019, 14)
    PyQt4.QtCore.QPoint(2385, 14)
    

