pyqt5鼠标点击 移动 d起监听案例

pyqt5鼠标点击 移动 d起监听案例,第1张

# -*- coding: utf-8 -*-

import io
import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import numpy as np
import cv2

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(675, 299)
        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(40, 60, 81, 51))
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.label_11 = QtWidgets.QLabel(Dialog)
        self.label_11.setGeometry(QtCore.QRect(520, 230, 91, 41))
        self.label_11.setAlignment(QtCore.Qt.AlignCenter)
        self.label_11.setObjectName("label_11")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "发音检测"))
        self.label.setText(_translate("Dialog", "Wold"))
        self.label_11.setText(_translate("Dialog", "Fricatives"))


class mwindow(QWidget, Ui_Dialog):
    def __init__(self):
        super(mwindow, self).__init__()
        self.setupUi(self)
    
    # 点击事件
    def mousePressEvent(self, event):
        # 获取鼠标点击的坐标
        x = event.x()
        y = event.y()
        # 鼠标点击的对象
        label = self.childAt(x, y)
        # 判断鼠标点击的对象是否为label
        if isinstance(label, QLabel):
            # 获取label的名字
            name = label.objectName()
            print("鼠标点击了",name)
            
    # 鼠标移动事件
    def mouseMoveEvent(self, event):
        # 获取鼠标移动的坐标
        x = event.x()
        y = event.y()
        print("鼠标移动了",x,y)
        
    # 鼠标松开事件
    def mouseReleaseEvent(self, event):
        # 获取鼠标松开的坐标
        x = event.x()
        y = event.y()
        # 鼠标松开的对象
        label = self.childAt(x, y)
        # 判断鼠标松开的对象是否为label
        if isinstance(label, QLabel):
            # 获取label的名字
            name = label.objectName()
            print("鼠标松开了",name)

if __name__ == '__main__':
    app=QApplication(sys.argv)
    #初始化窗口
    m=mwindow()
    m.show()
    sys.exit(app.exec_())


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/725370.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存