加载图片 :param pixmap: 图片或者图片路径 :param fitIn: 是否适应 :type pixmap: QPixmap or QImage or str :type fitIn: bool
(self, pixmap, fitIn=True)
| 63 | self.setBackgroundBrush(color) |
| 64 | |
| 65 | def setPixmap(self, pixmap, fitIn=True): |
| 66 | """加载图片 |
| 67 | :param pixmap: 图片或者图片路径 |
| 68 | :param fitIn: 是否适应 |
| 69 | :type pixmap: QPixmap or QImage or str |
| 70 | :type fitIn: bool |
| 71 | """ |
| 72 | if isinstance(pixmap, QPixmap): |
| 73 | self.pixmap = pixmap |
| 74 | elif isinstance(pixmap, QImage): |
| 75 | self.pixmap = QPixmap.fromImage(pixmap) |
| 76 | elif isinstance(pixmap, str) and os.path.isfile(pixmap): |
| 77 | self.pixmap = QPixmap(pixmap) |
| 78 | else: |
| 79 | return |
| 80 | self._item.setPixmap(self.pixmap) |
| 81 | self._item.update() |
| 82 | self.setSceneDims() |
| 83 | if fitIn: |
| 84 | self.fitInView(QRectF(self._item.pos(), QSizeF( |
| 85 | self.pixmap.size())), Qt.KeepAspectRatio) |
| 86 | self.update() |
| 87 | |
| 88 | def setSceneDims(self): |
| 89 | if not self.pixmap: |