在参考别人的基础上,改动不大,重新写了鼠标实现图片的移动、缩放、还原等功能,注释中写出来一些个人理解,欢迎小伙伴们提意见交流。具体代码如下:
# -*- coding: utf-8 -*-
"""
Created on Sun May 5 21:37:54 2019
@author: Tiny
"""
# =============================================================================
''' 鼠标左键移动图片,中键缩放图片,右键还原图片'''
''' 参考: 1. https://blog.csdn.net/fgh1991/article/details/89851327
PyQt5 鼠标点击事件(点击响应事件可自定义):鼠标单击、双击、滚轮滚动、释放、移动等
*2. https://github.com/SmileJET/utils-for-python/tree/master/image_with_mouse_control
Image with Mouse Control'''
# =============================================================================
# =============================================================================
''' PyQt4 和 PyQt5区别:'''
# PySide2.QtGui.QWheelEvent.delta()
# Return type: int
# This function has been deprecated, use pixelDelta() or angleDelta() instead.
''' 重点: '''
# 1. QPainter绘制框线(2019-5-5 20:20):
# QPainter的绘制操作在paintEvents(self, event)中完成,
# 且绘制方法必须放在QtGui.QPainter对象的begain() 和 end()之间
# 直接采用QPaniter.drawRect(int x, int y, int w, int h)反而不能绘制框线
# 2. 图片显示: QLabel vs. QPainter
# 个人认为前者实现静态显示较好; 后者实现动态显示较好。
# =============================================================================
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QWidget
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
'''定义主窗口'''
class myWindow(QWidget): # 不可用QMainWindow,因为QLabel继承自QWidget
def __init__(self):
super(myWindow, self).__init__()
self.res

实现图片的鼠标左键移动、中键缩放、右键还原等&spm=1001.2101.3001.5002&articleId=89888002&d=1&t=3&u=65e29ab284c94daf8aaad538d6963458)
2万+

被折叠的 条评论
为什么被折叠?



