我尝试创建一个程序来操作图像,我想要鼠标在 Qgraphicscene 中时的位置,但是除非我在 Qgraphicview 之外开始,否则不会触发鼠标事件,我怎样才能得到这个位置图像(像素)的坐标,感谢您的帮助
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.uic import *
from PIL import Image,ImageFilter,ImageQt
import sys
MainUI, _ = loadUiType('app.ui')
class MainApp(QMainWindow, MainUI):
def __init__(self):
super(MainApp, self).__init__()
QMainWindow.__init__(self)
self.setupUi(self)
def open_image(self):
img = QFileDialog.getOpenFileName(self, 'Open file',
'c:\\')
pixmap = QtGui.QPixmap(img[0])
self.scene = QtWidgets.QGraphicsScene()
self.item = QtWidgets.QGraphicsPixmapItem(pixmap)
self.scene.addItem(self.item)
self.graphicsView.setScene(self.scene)
self.image =Image.open(img[0])
def mouseMoveEvent(self,e):
print(e.pos())
def main():
app = QApplication(sys.argv)
windows = MainApp()
windows.show()
app.exec_()
if __name__ == '__main__':
main()