problem description
InPyQt5, 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