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