代码拉取完成,页面将自动刷新
同步操作将从 吉康毅/AI-base_live_text_recognition 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import ctypes
import os
from fastdeploy import vision
import cv2
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5.QtGui import QColor, QPalette, QIcon
from PyQt5.QtWidgets import QApplication, QFileDialog, QMessageBox, QToolTip
from PyQt5.QtCore import Qt, QTimer, QStringListModel, QPoint
from setting_window import Setting_MainWindow
import pyautogui
from model_in import ocrv3
det_model, cls_model, rec_model = ocrv3()
ppocr_v3 = vision.ocr.PPOCRv3(det_model=det_model, cls_model=cls_model, rec_model=rec_model)
width, height = pyautogui.size()
print("屏幕分辨率为:{}x{}".format(width, height))
class MainWindow(QtWidgets.QMainWindow, Setting_MainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setupUi(self) # 创建窗体对象
class Ui_MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(Ui_MainWindow, self).__init__()
self.jie = None
self.setupUi(self)
self.pandua = -1
self.kuangzuo = None
self.retranslateUi(self)
self.pat = None
self.n = 1
self.stade = 0
self.is_file = 0
self.is_sp = 0
self.is_kedian = 0
self.tip = 1
self.setMouseTracking(True)
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
# 设置左上角窗口图标
self.setWindowIcon(QIcon('./logo.png'))
# 设置任务栏图标
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
MainWindow.resize((width // 5) * 4, (height // 5) * 4)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout_2 = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout_2.setObjectName("gridLayout_2")
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.widget = QtWidgets.QWidget(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.widget.sizePolicy().hasHeightForWidth())
self.widget.setSizePolicy(sizePolicy)
self.widget.setObjectName("widget")
self.gridLayout_4 = QtWidgets.QGridLayout(self.widget)
self.gridLayout_4.setObjectName("gridLayout_4")
self.label_4 = QtWidgets.QLabel(self.widget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_4.sizePolicy().hasHeightForWidth())
self.label_4.setSizePolicy(sizePolicy)
self.label_4.setObjectName("label_4")
self.gridLayout_4.addWidget(self.label_4, 0, 0, 1, 1)
self.horizontalLayout.addWidget(self.widget)
spacerItem1 = QtWidgets.QSpacerItem(400, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
self.widget_2 = QtWidgets.QWidget(self.centralwidget)
self.widget_2.setObjectName("widget_2")
self.gridLayout_3 = QtWidgets.QGridLayout(self.widget_2)
self.gridLayout_3.setObjectName("gridLayout_3")
self.label_5 = QtWidgets.QLabel(self.widget_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_5.sizePolicy().hasHeightForWidth())
self.label_5.setSizePolicy(sizePolicy)
self.label_5.setText("")
self.label_5.setObjectName("label_5")
self.gridLayout_3.addWidget(self.label_5, 0, 0, 1, 1)
self.horizontalLayout.addWidget(self.widget_2)
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem2)
self.horizontalLayout.setStretch(0, 1)
self.horizontalLayout.setStretch(1, 10)
self.horizontalLayout.setStretch(3, 10)
self.horizontalLayout.setStretch(4, 1)
self.gridLayout.addLayout(self.horizontalLayout, 1, 0, 1, 2)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
self.pushButton.setStyleSheet("font: 13pt \"Microsoft Himalaya\";")
self.pushButton.setObjectName("pushButton")
self.horizontalLayout_3.addWidget(self.pushButton)
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth())
self.pushButton_2.setSizePolicy(sizePolicy)
self.pushButton_2.setStyleSheet("font: 13pt \"Microsoft Himalaya\";")
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout_3.addWidget(self.pushButton_2)
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
self.pushButton_3.setSizePolicy(sizePolicy)
self.pushButton_3.setStyleSheet("font: 13pt \"Microsoft Himalaya\";")
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout_3.addWidget(self.pushButton_3)
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_4.sizePolicy().hasHeightForWidth())
self.pushButton_4.setSizePolicy(sizePolicy)
self.pushButton_4.setStyleSheet("font: 13pt \"Microsoft Himalaya\";")
self.pushButton_4.setObjectName("pushButton_4")
self.horizontalLayout_3.addWidget(self.pushButton_4)
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_5.sizePolicy().hasHeightForWidth())
self.pushButton_5.setSizePolicy(sizePolicy)
self.pushButton_5.setStyleSheet("font: 13pt \"Microsoft Himalaya\";")
self.pushButton_5.setObjectName("pushButton_5")
self.horizontalLayout_3.addWidget(self.pushButton_5)
self.horizontalLayout_4.addLayout(self.horizontalLayout_3)
spacerItem3 = QtWidgets.QSpacerItem(50, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_4.addItem(spacerItem3)
self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_7.sizePolicy().hasHeightForWidth())
self.pushButton_7.setSizePolicy(sizePolicy)
self.pushButton_7.setStyleSheet("font: 13pt \"Microsoft Himalaya\";")
self.pushButton_7.setObjectName("pushButton_7")
self.horizontalLayout_4.addWidget(self.pushButton_7)
self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_6.sizePolicy().hasHeightForWidth())
self.pushButton_6.setSizePolicy(sizePolicy)
self.pushButton_6.setMaximumSize(QtCore.QSize(16777215, 16777215))
self.pushButton_6.setBaseSize(QtCore.QSize(0, 0))
self.pushButton_6.setStyleSheet("font: 13pt \"Microsoft Himalaya\";")
self.pushButton_6.setObjectName("pushButton_6")
self.horizontalLayout_4.addWidget(self.pushButton_6)
self.horizontalLayout_4.setStretch(0, 6)
self.horizontalLayout_4.setStretch(1, 4)
self.horizontalLayout_4.setStretch(2, 1)
self.horizontalLayout_4.setStretch(3, 1)
self.gridLayout.addLayout(self.horizontalLayout_4, 3, 1, 1, 1)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label = QtWidgets.QLabel(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setStyleSheet("font: 18pt \"Microsoft Himalaya\";")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.horizontalLayout_2.addWidget(self.label)
spacerItem4 = QtWidgets.QSpacerItem(400, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem4)
self.label_2 = QtWidgets.QLabel(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
self.label_2.setSizePolicy(sizePolicy)
self.label_2.setStyleSheet("font: 18pt \"Microsoft Himalaya\";")
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.horizontalLayout_2.addWidget(self.label_2)
self.gridLayout.addLayout(self.horizontalLayout_2, 0, 0, 1, 2)
spacerItem5 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.gridLayout.addItem(spacerItem5, 2, 1, 1, 1)
spacerItem6 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.gridLayout.addItem(spacerItem6, 4, 1, 1, 1)
self.listView = QtWidgets.QListView(self.centralwidget)
self.listModel = QStringListModel()
self.listView.setEnabled(True)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.listView.sizePolicy().hasHeightForWidth())
self.listView.setSizePolicy(sizePolicy)
self.listView.setObjectName("listView")
self.gridLayout.addWidget(self.listView, 5, 0, 1, 2)
self.gridLayout.setRowStretch(0, 1)
self.gridLayout.setRowStretch(1, 10)
self.gridLayout.setRowStretch(2, 1)
self.gridLayout.setRowStretch(3, 2)
self.gridLayout.setRowStretch(4, 1)
self.gridLayout.setRowStretch(5, 12)
self.gridLayout_2.addLayout(self.gridLayout, 0, 1, 1, 1)
spacerItem7 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem7, 0, 0, 1, 1)
spacerItem8 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout_2.addItem(spacerItem8, 0, 2, 1, 1)
self.gridLayout_2.setColumnStretch(0, 1)
self.gridLayout_2.setColumnStretch(1, 30)
self.gridLayout_2.setColumnStretch(2, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.pushButton.clicked.connect(self.show_log)
self.pushButton_2.clicked.connect(self.timestart)
self.pushButton_3.clicked.connect(self.back_z)
self.pushButton_4.clicked.connect(self.stop_z)
self.pushButton_5.clicked.connect(self.up_z)
self.pushButton_6.clicked.connect(self.show_setting)
self.pushButton_7.clicked.connect(self.clear)
background_color = QColor()
background_color.setNamedColor('#282821')
self.label_4.setAutoFillBackground(True)
palette = QPalette()
palette.setColor(QPalette.Window, background_color)
self.label_4.setPalette(palette)
self.label_4.setAlignment(Qt.AlignCenter)
background_color = QColor()
background_color.setNamedColor('#282821')
self.label_5.setAutoFillBackground(True)
palette = QPalette()
palette.setColor(QPalette.Window, background_color)
self.label_5.setPalette(palette)
self.label_5.setAlignment(Qt.AlignCenter)
self.setMouseTracking(True)
self.centralwidget.setMouseTracking(True)
self.widget_2.setMouseTracking(True)
self.label_5.setMouseTracking(True)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "文字识别"))
self.pushButton.setText(_translate("MainWindow", "选择照片/视频"))
self.pushButton_2.setText(_translate("MainWindow", "开始处理"))
self.pushButton_3.setText(_translate("MainWindow", "向前移动帧"))
self.pushButton_4.setText(_translate("MainWindow", "暂停"))
self.pushButton_5.setText(_translate("MainWindow", "向后移动帧"))
self.pushButton_7.setText(_translate("MainWindow", "清空"))
self.pushButton_6.setText(_translate("MainWindow", "设置"))
self.label.setText(_translate("MainWindow", "原视频/图片"))
self.label_2.setText(_translate("MainWindow", "实时处理"))
def show_setting(self):
window2.show()
if window2.str:
self.colse()
def show_log(self):
file_path, _ = QFileDialog.getOpenFileName(self, '打开文件', './results', '*')
extension = os.path.splitext(file_path)[-1].replace('.', '')
if extension in ['jpg', 'bmp', 'png', 'jpeg', 'jfif']:
self.is_file = 1
self.is_sp = 0
self.jiazai_img_1(cv2.imread(file_path), True)
elif extension in ['mp4', 'MP4', 'AVI', 'MOV', 'ASF', 'WMV', 'RM', 'RMVB', 'FLV', 'F4V']:
self.is_file = 1
self.is_sp = 1
self.pat = file_path
self.jiazai_sp_1()
def jiazai_img_1(self, frame, adj):
frame = cv2.resize(frame, (500, int((500 / frame.shape[1]) * frame.shape[0])), interpolation=cv2.INTER_LINEAR)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
img = QtGui.QImage(frame, frame.shape[1], frame.shape[0], QtGui.QImage.Format_RGB888)
ratio = min(self.label_4.width() / frame.shape[1], self.label_4.height() / frame.shape[0])
self.pm = QtGui.QPixmap.fromImage(img).scaled(int(frame.shape[1] * ratio), int(frame.shape[0] * ratio)) # 缩放图像
self.label_4.setPixmap(self.pm)
if adj:
result = ppocr_v3.predict(frame)
# print(result)
vis_im = vision.vis_ppocr(frame, result)
print(vis_im.shape)
self.jiazai_img_2(vis_im)
self.jie = []
self.kuangzuo = []
self.is_kedian = 1
for i in str(result).split('\n'):
dan_ge_li = i.split('rec text: ')
det_boxes = dan_ge_li[0].replace('det boxes: ', '').replace('[[', '').replace(']]', '').split('],[')
if len(dan_ge_li) > 1 and len(det_boxes) > 1:
kuan_li = []
gao_li = []
for fg in det_boxes:
shuf = fg.split(',')
kuan_li.append(int(shuf[0]))
gao_li.append(int(shuf[-1]))
rec_text = dan_ge_li[-1].split(' rec score:')[0]
label_width = self.label_5.width()
label_height = self.label_5.height()
if label_width / label_height > vis_im.shape[1] / vis_im.shape[0]:
bei_lv = label_height / vis_im.shape[0]
else:
bei_lv = label_width / vis_im.shape[1]
min_kuan = int(((min(kuan_li) - (vis_im.shape[1] / 2)) * bei_lv) + (0.5 * label_width))
max_kuan = int(((max(kuan_li) - (vis_im.shape[1] / 2)) * bei_lv) + (0.5 * label_width))
min_gao = int(((min(gao_li) - (vis_im.shape[0] / 2)) * bei_lv) + (0.5 * label_height))
max_gao = int(((max(gao_li) - (vis_im.shape[0] / 2)) * bei_lv) + (0.5 * label_height))
self.kuangzuo.append([[min_kuan, max_kuan], [min_gao, max_gao]])
self.jie.append(rec_text)
# 设计列表模型内容
self.listModel.setStringList(self.jie)
self.listView.setModel(self.listModel)
def jiazai_img_2(self, frame):
frame = cv2.resize(frame, (500, int((500 / frame.shape[1]) * frame.shape[0])), interpolation=cv2.INTER_LINEAR)
# frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
img = QtGui.QImage(frame, frame.shape[1], frame.shape[0], QtGui.QImage.Format_RGB888)
ratio = min(self.label_4.width() / frame.shape[1], self.label_4.height() / frame.shape[0])
self.pm = QtGui.QPixmap.fromImage(img).scaled(int(frame.shape[1] * ratio), int(frame.shape[0] * ratio)) # 缩放图像
self.label_5.setPixmap(self.pm)
def jiazai_sp_1(self):
self.cap = cv2.VideoCapture(self.pat)
self.frame_count = self.cap.get(cv2.CAP_PROP_FRAME_COUNT) # 视频帧数
net, img_fist = self.cap.read()
self.jiazai_img_1(img_fist, False)
self.timer1 = QTimer(self)
self.timer1.timeout.connect(self.timer_TimeOut)
def timestart(self):
if not self.is_sp:
self.warning_Event_2()
else:
if not self.is_file:
self.warning_Event()
else:
self.stade = 1
self.timer1.start(30.66667) # 单位为毫秒
def timepause(self):
if not self.is_sp:
self.warning_Event_2()
else:
if not self.is_file:
self.warning_Event()
else:
self.stade = 0
self.timer1.stop()
def timer_TimeOut(self):
if self.n >= self.frame_count:
self.n = 1
self.timepause()
self.cap = cv2.VideoCapture(self.pat)
ret, frame = self.cap.read()
self.jiazai_img_1(frame, True)
self.n = self.n + 1
def back_z(self):
if not self.is_sp:
self.warning_Event_2()
else:
if not self.is_file:
self.warning_Event()
else:
if self.n > 2:
self.timepause()
self.cap.set(cv2.CAP_PROP_POS_FRAMES, self.cap.get(cv2.CAP_PROP_POS_FRAMES) - 2)
ret, frame = self.cap.read()
self.jiazai_img_1(frame, True)
self.n = self.n - 1
else:
self.cap = cv2.VideoCapture(self.pat)
self.n = 1
def up_z(self):
if not self.is_sp:
self.warning_Event_2()
else:
if not self.is_file:
self.warning_Event()
else:
if self.frame_count > self.n + 2:
self.timepause()
self.cap.set(cv2.CAP_PROP_POS_FRAMES, self.cap.get(cv2.CAP_PROP_POS_FRAMES) + 2)
ret, frame = self.cap.read()
self.jiazai_img_1(frame, True)
self.n = self.n + 3
else:
self.cap.set(cv2.CAP_PROP_POS_FRAMES, self.frame_count - 1)
self.n = self.frame_count - 1
def stop_z(self):
if not self.is_sp:
self.warning_Event_2()
else:
if not self.is_file:
self.warning_Event()
else:
if self.stade:
self.timepause()
else:
self.timestart()
# 警告
def warning_Event(self): # 关闭窗口触发以下事件
QMessageBox.critical(self, "错误", "请先上传照片或视频!!")
def warning_Event_2(self): # 关闭窗口触发以下事件
QMessageBox.critical(self, "错误", "请先上传视频!!")
# 清空
def clear(self):
self.timepause()
self.label_4.clear()
self.label_5.clear()
self.listModel.setStringList([])
self.listView.setModel(self.listModel)
self.is_file = 0
self.is_kedian = 0
def mouseMoveEvent(self, event):
# 获取照片在窗口中的全局坐标位置
photo_pos = self.label_5.mapToGlobal(QPoint(0, 0))
# 获取鼠标点击事件的坐标位置
mouse_pos = event.globalPos()
# 将鼠标坐标转换为相对于照片的局部坐标
relative_pos = mouse_pos - photo_pos
x, y = relative_pos.x(), relative_pos.y()
self.pandua = -1
if self.is_kedian:
ji_lu = 0
for i in self.kuangzuo:
if (i[0][0] < x < i[0][-1]) and (i[-1][0] < y < i[-1][-1]):
self.pandua = ji_lu
QToolTip.showText(event.globalPos(), f'点击复制以下文本:{self.jie[ji_lu]}', self)
# break
else:
QToolTip.hideText()
ji_lu = ji_lu + 1
def mousePressEvent(self, event):
if self.pandua != -1:
if event.button() == Qt.LeftButton:
print('复制成功')
clipboard = QApplication.clipboard()
clipboard.setText(self.jie[self.pandua])
if __name__ == '__main__':
app = QApplication(sys.argv)
win = Ui_MainWindow()
win.setMouseTracking(True)
window2 = MainWindow()
win.show()
sys.exit(app.exec_())
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。