The mouse positions of QGraphicsScene getting mousePressEvent events in PyQt5 are all 0.0.

problem description

In

PyQt5, if you want to get the mouse position in the mousePressEvent of QGraphicsScene, no matter where you click, the display is [0. 010. 0]

.

the environmental background of the problems and what methods you have tried

No similar problem was found on the Internet

related codes

/ / Please paste the code text below (do not replace the code with pictures)

-sharpQGraphicsScene
class CARscene(QtWidgets.QGraphicsScene):
    def __init__(self, parent=None):
        super(CARscene, self).__init__(parent)

    def mousePressEvent(self, QMouseEvent):
        -sharp[0.0, 0.0]
        print([QMouseEvent.pos().x(), QMouseEvent.pos().y()])

-sharpQtDesigner    
class CDataMingQtUi(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
    super(CDataMingQtUi, self).__init__()
    self.setupUi(self)

    -sharpCARgraphview QGraphicView
    self.figure = plt.figure()
    self.canvas = FigureCanvas(self.figure)
    self.graph_sence = CARscene()
    self.graph_sence.addWidget(self.canvas)
    self.CARgraphview.setScene(self.graph_sence)
    

what result do you expect? What is the error message actually seen?

expect to show the coordinates of the mouse click
the actual display is [0.0,0.0], which is the value wherever you click

.
Mar.26,2021

use scenePos instead

def mousePressEvent(self, event):
    QGraphicsScene.mousePressEvent(self, event)
    e = event.scenePos()
    print(e)

one, introduce QCursor
from PyQt5.Qt import QCursor

two. Bind eventFilter
self.pb_heading.installEventFilter (self) of this class

3, pop-up window at qevent.pos (), that is, mouse position
def eventFilter (self, qobject, qevent):

    qtype = qevent.type()
    -sharp ~ print(qtype)
    -sharp ~ if qtype == QEvent.HoverMove:
    if qtype == QEvent.HoverLeave:
        print("HoverLeave")
        return True
    elif qtype == QEvent.HoverEnter:
        print("HoverEnter")
        print(qevent.pos())
        self.on_pb_heading_clicked(qevent.pos())
        return True
    else:
        return False
Menu