MCPcopy
hub / github.com/PyQt5/PyQt / fitInView

Method fitInView

QListView/ImageView.py:94–113  ·  view source on GitHub ↗

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

(self, rect, flags=Qt.IgnoreAspectRatio)

Source from the content-addressed store, hash-verified

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

Callers 1

setPixmapMethod · 0.95

Calls 2

widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected