Я пытаюсь использовать событие mousemove в графическом представлении c в python 3.7, но def mousemoveevent не работает.
Мой код выглядит следующим образом, что-то не так?
from PyQt5.QtCore import QEvent
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setWindowModality(QtCore.Qt.WindowModal)
MainWindow.setEnabled(True)
MainWindow.resize(1228, 844)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setMaximumSize(QtCore.QSize(1228, 844))
MainWindow.setBaseSize(QtCore.QSize(1920, 1080))
font = QtGui.QFont()
font.setFamily("MS Shell Dlg 2")
MainWindow.setFont(font)
MainWindow.setFocusPolicy(QtCore.Qt.NoFocus)
MainWindow.setAnimated(True)
MainWindow.setDockOptions(QtWidgets.QMainWindow.AllowTabbedDocks|QtWidgets.QMainWindow.AnimatedDocks)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(0, 0, 1920, 1080))
self.tabWidget.setMouseTracking(False)
self.tabWidget.setAutoFillBackground(False)
self.tabWidget.setTabPosition(QtWidgets.QTabWidget.North)
self.tabWidget.setTabShape(QtWidgets.QTabWidget.Rounded)
self.tabWidget.setIconSize(QtCore.QSize(20, 20))
self.tabWidget.setElideMode(QtCore.Qt.ElideNone)
self.tabWidget.setUsesScrollButtons(False)
self.tabWidget.setDocumentMode(False)
self.tabWidget.setTabsClosable(False)
self.tabWidget.setMovable(True)
self.tabWidget.setTabBarAutoHide(False)
self.tabWidget.setObjectName("tabWidget")
self.DATABASETAB = QtWidgets.QWidget()
self.DATABASETAB.setObjectName("DATABASETAB")
self.LOADBASE = QtWidgets.QPushButton(self.DATABASETAB)
self.LOADBASE.setGeometry(QtCore.QRect(20, 110, 155, 50))
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
font.setKerning(True)
self.LOADBASE.setFont(font)
self.LOADBASE.setObjectName("LOADBASE")
self.COPYBASE = QtWidgets.QPushButton(self.DATABASETAB)
self.COPYBASE.setGeometry(QtCore.QRect(20, 170, 155, 50))
self.COPYBASE.setCheckable(False)
self.COPYBASE.setObjectName("COPYBASE")
self.DELETEBASE = QtWidgets.QPushButton(self.DATABASETAB)
self.DELETEBASE.setGeometry(QtCore.QRect(20, 230, 155, 50))
self.DELETEBASE.setObjectName("DELETEBASE")
self.CREATEDB = QtWidgets.QPushButton(self.DATABASETAB)
self.CREATEDB.setGeometry(QtCore.QRect(20, 50, 155, 50))
self.CREATEDB.setObjectName("CREATEDB")
self.SAVE = QtWidgets.QPushButton(self.DATABASETAB)
self.SAVE.setGeometry(QtCore.QRect(20, 290, 155, 50))
self.SAVE.setObjectName("SAVE")
self.lineEdit = QtWidgets.QLineEdit(self.DATABASETAB)
self.lineEdit.setGeometry(QtCore.QRect(230, 50, 521, 50))
self.lineEdit.setObjectName("lineEdit")
self.label_2 = QtWidgets.QLabel(self.DATABASETAB)
self.label_2.setGeometry(QtCore.QRect(230, 20, 271, 21))
font = QtGui.QFont()
font.setPointSize(11)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.tabWidget.addTab(self.DATABASETAB, "")
self.CAMERATAB = QtWidgets.QWidget()
self.CAMERATAB.setObjectName("CAMERATAB")
self.label = QtWidgets.QLabel(self.CAMERATAB)
self.label.setGeometry(QtCore.QRect(10, 0, 301, 71))
font = QtGui.QFont()
font.setPointSize(10)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.VIEWSLIST = QtWidgets.QListView(self.CAMERATAB)
self.VIEWSLIST.setGeometry(QtCore.QRect(20, 60, 281, 691))
self.VIEWSLIST.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.VIEWSLIST.setObjectName("VIEWSLIST")
self.CAPTURAR = QtWidgets.QPushButton(self.CAMERATAB)
self.CAPTURAR.setGeometry(QtCore.QRect(330, 60, 201, 61))
self.CAPTURAR.setObjectName("CAPTURAR")
self.CUTIMAGE = QtWidgets.QPushButton(self.CAMERATAB)
self.CUTIMAGE.setGeometry(QtCore.QRect(330, 140, 201, 61))
self.CUTIMAGE.setObjectName("CUTIMAGE")
self.SAVEIMAGE = QtWidgets.QPushButton(self.CAMERATAB)
self.SAVEIMAGE.setGeometry(QtCore.QRect(330, 220, 201, 61))
self.SAVEIMAGE.setObjectName("SAVEIMAGE")
self.VISTAVIEWER = QtWidgets.QGraphicsView(self.CAMERATAB)
self.VISTAVIEWER.setGeometry(QtCore.QRect(330, 300, 881, 451))
self.VISTAVIEWER.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.CrossCursor))
self.VISTAVIEWER.setMouseTracking(True)
self.VISTAVIEWER.setAcceptDrops(True)
self.VISTAVIEWER.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.VISTAVIEWER.setFrameShadow(QtWidgets.QFrame.Sunken)
self.VISTAVIEWER.setLineWidth(7)
self.VISTAVIEWER.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.VISTAVIEWER.setObjectName("VISTAVIEWER")
self.tabWidget.addTab(self.CAMERATAB, "")
self.ZONETAB = QtWidgets.QWidget()
self.ZONETAB.setObjectName("ZONETAB")
self.AUTOMATICZONES = QtWidgets.QPushButton(self.ZONETAB)
self.AUTOMATICZONES.setGeometry(QtCore.QRect(10, 30, 241, 51))
self.AUTOMATICZONES.setLayoutDirection(QtCore.Qt.LeftToRight)
self.AUTOMATICZONES.setAutoExclusive(False)
self.AUTOMATICZONES.setAutoDefault(False)
self.AUTOMATICZONES.setDefault(False)
self.AUTOMATICZONES.setFlat(False)
self.AUTOMATICZONES.setObjectName("AUTOMATICZONES")
self.MANUALZONES = QtWidgets.QPushButton(self.ZONETAB)
self.MANUALZONES.setGeometry(QtCore.QRect(270, 30, 241, 51))
self.MANUALZONES.setObjectName("MANUALZONES")
self.graphicsView = QtWidgets.QGraphicsView(self.ZONETAB)
self.graphicsView.setGeometry(QtCore.QRect(10, 100, 1201, 691))
self.graphicsView.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.CrossCursor))
self.graphicsView.setMouseTracking(True)
self.graphicsView.setObjectName("graphicsView")
self.NOMBREZONA = QtWidgets.QLineEdit(self.ZONETAB)
self.NOMBREZONA.setGeometry(QtCore.QRect(540, 41, 241, 41))
self.NOMBREZONA.setObjectName("NOMBREZONA")
# self.NOMBREZONA.setText("dddd")
self.label_3 = QtWidgets.QLabel(self.ZONETAB)
self.label_3.setGeometry(QtCore.QRect(540, 20, 151, 16))
font = QtGui.QFont()
font.setPointSize(9)
self.label_3.setFont(font)
self.label_3.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.label_3.setObjectName("label_3")
self.APLICARNAME = QtWidgets.QPushButton(self.ZONETAB)
self.APLICARNAME.setGeometry(QtCore.QRect(800, 50, 93, 28))
self.APLICARNAME.setObjectName("APLICARNAME")
self.tabWidget.addTab(self.ZONETAB, "")
self.ELEMENTTAB = QtWidgets.QWidget()
self.ELEMENTTAB.setObjectName("ELEMENTTAB")
self.tabWidget.addTab(self.ELEMENTTAB, "")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(2)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "ADVANCED VISION TEST SYSTEM"))
self.LOADBASE.setText(_translate("MainWindow", "CARGAR BASE DE DATOS"))
self.COPYBASE.setText(_translate("MainWindow", "COPIAR BASE DE DATOS"))
self.DELETEBASE.setText(_translate("MainWindow", "BORRAR BASE DE DATOS"))
self.CREATEDB.setText(_translate("MainWindow", "CREAR BASE DE DATOS"))
self.SAVE.setText(_translate("MainWindow", "GUARDAR CAMBIOS"))
self.label_2.setText(_translate("MainWindow", "BASE DE DATOS SELECCIONADA:"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.DATABASETAB), _translate("MainWindow", "BASES DE DATOS"))
self.label.setText(_translate("MainWindow", "SELECCIONA LA VISTA A CAPTURAR"))
self.CAPTURAR.setText(_translate("MainWindow", "CAPTURAR IMAGEN"))
self.CUTIMAGE.setText(_translate("MainWindow", "CORTAR IMAGEN"))
self.SAVEIMAGE.setText(_translate("MainWindow", "GUARDAR CAPTURA"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.CAMERATAB), _translate("MainWindow", "CONFIGURAR CAPTURAS"))
self.AUTOMATICZONES.setText(_translate("MainWindow", "DEFINICION AUTOMATICA DE ZONAS"))
self.MANUALZONES.setText(_translate("MainWindow", "DEFINICION MANUAL DE ZONAS"))
self.label_3.setText(_translate("MainWindow", "NOMBRE DE LA ZONA:"))
self.APLICARNAME.setText(_translate("MainWindow", "APLICAR"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.ZONETAB), _translate("MainWindow", "ZONAS"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.ELEMENTTAB), _translate("MainWindow", "ELEMENTOS"))
class MyForm(QDialog):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.show()
def mouseMoveEvent(self, event):
print("ddddd")
x = event.x()
y = event.y()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
Ui_MainWindow().setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())