MCPcopy Index your code
hub / github.com/PyQt5/PyQt / fitInView

Method fitInView

QGraphicsView/ImageView.py:93–112  ·  view source on GitHub ↗

剧中适应 :param rect: 矩形范围 :param flags: :return:

(self, rect, flags=Qt.IgnoreAspectRatio)

Source from the content-addressed store, hash-verified

91 self.setSceneRect(QRectF(QPointF(0, 0), QPointF(self.pixmap.width(), self.pixmap.height())))
92
93 def fitInView(self, rect, flags=Qt.IgnoreAspectRatio):
94 """剧中适应
95 :param rect: 矩形范围
96 :param flags:
97 :return:
98 """
99 if not self.scene() or rect.isNull():
100 return
101 unity = self.transform().mapRect(QRectF(0, 0, 1, 1))
102 self.scale(1 / unity.width(), 1 / unity.height())
103 viewRect = self.viewport().rect()
104 sceneRect = self.transform().mapRect(rect)
105 x_ratio = viewRect.width() / sceneRect.width()
106 y_ratio = viewRect.height() / sceneRect.height()
107 if flags == Qt.KeepAspectRatio:
108 x_ratio = y_ratio = min(x_ratio, y_ratio)
109 elif flags == Qt.KeepAspectRatioByExpanding:
110 x_ratio = y_ratio = max(x_ratio, y_ratio)
111 self.scale(x_ratio, y_ratio)
112 self.centerOn(rect.center())
113
114 def wheelEvent(self, event):
115 if event.angleDelta().y() > 0:

Callers 1

setPixmapMethod · 0.95

Calls 2

widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected