QGraphicsView鼠标拖动setSceneRect失灵问题
问题
场景:实现放大缩小功能的同时,能够通过鼠标自由拖动。
问题:当放大时拖动异常,缩小的时候能够正常拖动
可执行版本
import sys
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtGui import QFont, QFontMetrics
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QHBoxLayout, QGraphicsScene, QGraphicsView
from PyQt5.QtCore import QRectF
class ImageView(QtWidgets.QGraphicsItem):
def __init__(self, parent=None):
super().__init__(parent)
self.__image = None
def load_image(self, image:QtGui.QPixmap):
self.__image = image
def boundingRect(self) -> QtCore.QRectF:
if self.__image is not None:
w = self.__image.width()
h = self.__image.height()
return QRectF(0,0,w,h)
else:
return QtWidgets.QGraphicsItem.boundingRect()
def paint(self, painter: QtGui.QPainter, option, widget) -> None:
if self.__image is not None:
w = self.__image.width()
h = self.__image.height()
painter.drawPixmap(0,0