def convert_bitmap(image, width=None, height=None): pix = None if isinstance(image, ImageResource): pix = traitsui_convert_bitmap(image) elif isinstance(image, Image): # image = image.convert('RGBA') data = image.tostring('raw', 'RGBA') im = QImage(data, image.size[0], image.size[1], QImage.Format_ARGB32) pix = QPixmap.fromImage(QImage.rgbSwapped(im)) else: s = image.shape if len(s) >= 2: # im = QImage(image.tostring(),s[1], s[0], QImage.Format_RGB888) im = QImage(image, s[1], s[0], QImage.Format_RGB888) pix = QPixmap.fromImage(QImage.rgbSwapped(im)) else: pix = QPixmap() if pix: if width > 0 and height > 0: pix = pix.scaled(width, height) elif width > 0: pix = pix.scaledToWidth(width) if height > 0: pix = pix.scaledToHeight(height) return pix
def requestPixmap(self, path, rsize, size): """@reimp @public @param[in] providerId unicode unused @param[out] rsize QSize @param[in] size QSize @return QPixmap not None virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) """ ret = QPixmap(QUrl(path).toLocalFile()) if ret.isNull(): derror("failed to load image: '%s'" % path) elif size != ret.size() and not size.isEmpty() and not ret.size( ).isEmpty(): if ret.width() * size.height() > ret.height() * size.width(): ret = ret.scaledToHeight(min(800, size.height()), Qt.SmoothTransformation) else: w = 1000 if ret.width() > ret.height() else 600 ret = ret.scaledToWidth(min(w, size.width()), Qt.SmoothTransformation) #elif size != ret.size(): # ret = (ret.scaled(size, Qt.KeepAspectRatio, Qt.SmoothTransformation) if not size.isEmpty() else # ret.scaledToWidth(size.width(), Qt.SmoothTransformation) if size.width() > 0 else # ret.scaledToHeight(size.height(), Qt.SmoothTransformation) if size.height() > 0 else # ret) rsize.setWidth(ret.width()) rsize.setHeight(ret.height()) return ret
def drawWidget(self, painter): if self.isHighlighted: painter.setOpacity(1.0) else: painter.setOpacity(0.5) pixmap = QPixmap(self.icon) pixmap = pixmap.scaledToWidth(self.width(), Qt.SmoothTransformation) painter.drawPixmap(self.rect(), pixmap)
def convert_bitmap(image, width=None, height=None): if isinstance(image, ImageResource): pix = traitsui_convert_bitmap(image) elif isinstance(image, Image): data = image.tostring('raw', 'RGBA') im = QImage(data, image.size[0], image.size[1], QImage.Format_ARGB32) pix = QPixmap.fromImage(QImage.rgbSwapped(im)) else: s = image.shape if len(s) >= 2: pix = QPixmap.fromImage(array2qimage(image)) else: pix = QPixmap() if pix: if width > 0 and height > 0: pix = pix.scaled(width, height) elif width > 0: pix = pix.scaledToWidth(width) if height > 0: pix = pix.scaledToHeight(height) return pix
def requestPixmap(self, name, rsize, size): """@reimp @public @param[in] providerId unicode unused @param[out] rsize QSize @param[in] size QSize @return QPixmap not None virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) """ ret = QPixmap(rc.image_path(name)) if ret.isNull(): derror("failed to load image: '%s'" % name) elif ret.size() != size: ret = ( ret.scaled(size, Qt.KeepAspectRatio, Qt.SmoothTransformation) if not size.isEmpty() else ret.scaledToWidth( size.width(), Qt.SmoothTransformation) if size.width() > 0 else ret.scaledToHeight(size.height(), Qt.SmoothTransformation) if size.height() > 0 else ret) rsize.setWidth(ret.width()) rsize.setHeight(ret.height()) return ret