本文整理汇总了Python中PySide.QtGui.QPixmap.scaled方法的典型用法代码示例。如果您正苦于以下问题:Python QPixmap.scaled方法的具体用法?Python QPixmap.scaled怎么用?Python QPixmap.scaled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPixmap
的用法示例。
在下文中一共展示了QPixmap.scaled方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_bitmap
# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import scaled [as 别名]
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
示例2: decoration
# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import scaled [as 别名]
def decoration(self, index):
"""Defines the decoration of the node.
Tries to load a banner from the URL, defined by :py:meth:`banner_url`,
sets a default image while loading and in case the attempt to
obtain a banner was unsuccesful. If a banner has been cached for the
given URL, the cached image will be used instead.
:param index: The index referring to the node to get decoration for.
:type index: :class:`~.PySide.QtCore.QModelIndex`
:returns: The :class:`PySide.QtGui.Pixmap` to use as the node's decoration.
"""
pixmap = QPixmap()
banner_url = self.banner_url()
if banner_url:
placeholder = ":/icons/image-loading.png"
fetch = True
else:
banner_url = placeholder = ":/icons/image-missing.png"
fetch = False
if not pixmap_cache.find(banner_url, pixmap):
if fetch:
banner_loader.fetch_banner(banner_url, index, self._cache)
pixmap.load(placeholder)
if self._scale:
pixmap = pixmap.scaled(self._scale, Qt.AspectRatioMode.KeepAspectRatio)
pixmap_cache.insert(banner_url, pixmap)
return pixmap
示例3: apply
# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import scaled [as 别名]
def apply(self, value):
if isinstance(value, basestring):
value = QPixmap(value)
assert isinstance(value, QPixmap), "Image bridge must be assigned a pixmap"
if self.width and self.height:
value = value.scaled(self.width, self.height)
self.widget.setPixmap(value)
示例4: paintEvent
# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import scaled [as 别名]
def paintEvent(self, pe):
painter = QPainter(self)
icon = QPixmap(self._icon)
icon = icon.scaled(self.size(), Qt.IgnoreAspectRatio)
if not self._mouse_over or not self._enabled:
painter.setOpacity(self._normal_opacity)
else:
painter.setOpacity(self._hover_opacity)
painter.drawPixmap(0, 0, icon)
示例5: paint
# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import scaled [as 别名]
def paint(self, painter, option, index):
if index.column() != 0: # not the image column
super(ScrapeItemDelegate, self).paint(painter, option, index)
else:
images = index.data(role=Qt.DisplayRole)
if images:
# yep. Make an image appear here
image_data = images[0] # assuming a single image for now
pixmap = QPixmap(image_data.get("path"))
pixmap = pixmap.scaled(self.max_cell_res[0], self.max_cell_res[1], Qt.IgnoreAspectRatio)
cell_rect = option.rect
painter.drawPixmap(cell_rect.x(), cell_rect.y(), pixmap)
else:
super(ScrapeItemDelegate, self).paint(painter, option, index)
示例6: fill_ranking
# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import scaled [as 别名]
def fill_ranking(self):
rank = self.generation.ranking
best = rank.ranking[0]
rest = rank.ranking[1:]
rx = QRegExp("pok\d+")
best_pokelabels = self.ranking.findChildren(QtGui.QLabel, rx)
for idx, pokename in enumerate(best.team_names):
pixmap = QPixmap("./sprites/" + pokename + ".png")
pixmap = pixmap.scaled(60, 40, QtCore.Qt.KeepAspectRatio)
best_pokelabels[idx].setPixmap(pixmap)
rx = QRegExp("poketeam_\d+")
pop_teams = self.ranking.findChildren(QtGui.QWidget, rx)
for g in range(len(rest)):
plabel = pop_teams[g].findChildren(QtGui.QLabel)
for idx, pokename in enumerate(rest[g].team_names):
pixmap = QPixmap("./sprites/" + pokename + ".png")
plabel[idx].setPixmap(pixmap)
示例7: ImageWidget
# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import scaled [as 别名]
class ImageWidget(QWidget):
"""
A widget that displays an image.
"""
def __init__(self, imagePath, fill=True, parent=None):
"""
Args:
imagePath : a system path that points to an image fles
fill : boolean that when True, makes the image fill the widget, whatever
the current widget size. When False, just draws the image at it's original
size.
"""
super(ImageWidget, self).__init__(parent)
assert imagePath != None, self.tr("Invalid image path")
self._image_pixmap = QPixmap(path.normpath(imagePath))
self._fill = fill
def paintEvent(self, pe):
painter = QPainter(self)
if self._fill:
scaled_pixmap = self._image_pixmap.scaled(self.size(), Qt.IgnoreAspectRatio)
painter.drawPixmap(0, 0, scaled_pixmap)
else:
painter.drawPixmap(0, 0, self._image_pixmap)
示例8: MdiArea
# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import scaled [as 别名]
#.........这里部分代码省略.........
"""
Handles the ``paintEvent`` event for :class:`MdiArea`.
:param `event`: A `QPaintEvent`_ to be processed.
"""
vport = self.viewport()
rect = vport.rect()
painter = QPainter(vport)
painter.setRenderHint(painter.SmoothPixmapTransform)
# Always fill with a solid color first
if self.useColor:
# painter.fillRect(rect, self.colorBrush)
painter.fillRect(rect, self.bgColor)
else:
painter.fillRect(rect, self.background())
# Then overlay the texture
if self.useTexture:
# painter.fillRect(rect, self.backgroundBrush)
bgBrush = QBrush(self.bgTexture)
painter.fillRect(rect, bgBrush)
# Overlay the logo last
if self.useLogo:
if not len(self.subWindowList()): # Nothing is open.
cSizeW, cSizeH = rect.width(), rect.height()
bgLogoW, bgLogoH = self.bgLogo.width(), self.bgLogo.height()
if bgLogoW > cSizeW:
# Proportional Scaling an Image.
newHeight = bgLogoH * cSizeW // bgLogoW
scaledLogo = self.bgLogo.scaled(cSizeW, newHeight)
painter.drawPixmap(0,
cSizeH // 2 - scaledLogo.height() // 2,
scaledLogo)
else:
painter.drawPixmap((cSizeW - bgLogoW) // 2,
(cSizeH - bgLogoH) // 2,
self.bgLogo)
else:
# Center the pixmap
dx = (rect.width() - self.bgLogo.width()) / 2
dy = (rect.height() - self.bgLogo.height()) / 2
painter.drawPixmap(dx, dy,
self.bgLogo.width(), self.bgLogo.height(),
self.bgLogo)
def zoomExtentsAllSubWindows(self):
"""
TOWRITE
"""
for window in self.subWindowList(): # foreach(QMdiSubWindow* window, subWindowList())
mdiWin = window # MdiWindow* mdiWin = qobject_cast<MdiWindow*>(window);
if mdiWin:
v = mdiWin.getView() # View*
if v:
v.recalculateLimits()
v.zoomExtents()
def forceRepaint(self):
"""
TOWRITE
"""
# HACK: Take that QMdiArea!
示例9: print
# 需要导入模块: from PySide.QtGui import QPixmap [as 别名]
# 或者: from PySide.QtGui.QPixmap import scaled [as 别名]
if 'coords' in self.flags:
print('x: {:.2f} {}'.format(x*scale, units))
print('y: {:.2f} {}'.format(y*scale, units))
print('angle: {:.2f} degrees'.format(angle))
def draw_line(self, linef):
line = QGraphicsLineItem(linef)
line.setPen(QPen(QBrush(QColor(0, 0, 0)), 1))
self.addItem(line)
if __name__ == '__main__':
app = QApplication(sys.argv)
loader = QUiLoader()
ui = loader.load('line_gui.ui')
ui.show()
pixmap = QPixmap(u'Top.jpg')
pixmap = pixmap.scaled(2*pixmap.size())
scene = GraphicsScene('tricavity', ['axis', 'coords'], scale_triplet=(.55,3.04,3.08))
pix_item = scene.addPixmap(pixmap)
pix_item.setCursor(Qt.CrossCursor)
layout = ui.findChild(QGridLayout, 'gridLayout')
view = QGraphicsView(scene)
layout.addWidget(view)
app.exec_()