本文整理汇总了Python中PyQt4.QtGui.QGraphicsPixmapItem.setPixmap方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsPixmapItem.setPixmap方法的具体用法?Python QGraphicsPixmapItem.setPixmap怎么用?Python QGraphicsPixmapItem.setPixmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsPixmapItem
的用法示例。
在下文中一共展示了QGraphicsPixmapItem.setPixmap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EditLinksNode
# 需要导入模块: from PyQt4.QtGui import QGraphicsPixmapItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPixmapItem import setPixmap [as 别名]
class EditLinksNode(QGraphicsWidget):
"""
A Node representation with channel anchors.
`direction` specifies the layout (default `Qt.LeftToRight` will
have icon on the left and channels on the right).
"""
def __init__(self, parent=None, direction=Qt.LeftToRight,
node=None, icon=None, iconSize=None, **args):
QGraphicsWidget.__init__(self, parent, **args)
self.setAcceptedMouseButtons(Qt.NoButton)
self.__direction = direction
self.setLayout(QGraphicsLinearLayout(Qt.Horizontal))
# Set the maximum size, otherwise the layout can't grow beyond its
# sizeHint (and we need it to grow so the widget can grow and keep the
# contents centered vertically.
self.layout().setMaximumSize(QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX))
self.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.MinimumExpanding)
self.__iconSize = iconSize or QSize(64, 64)
self.__icon = icon
self.__iconItem = QGraphicsPixmapItem(self)
self.__iconLayoutItem = GraphicsItemLayoutItem(item=self.__iconItem)
self.__channelLayout = QGraphicsGridLayout()
self.__channelAnchors = []
if self.__direction == Qt.LeftToRight:
self.layout().addItem(self.__iconLayoutItem)
self.layout().addItem(self.__channelLayout)
channel_alignemnt = Qt.AlignRight
else:
self.layout().addItem(self.__channelLayout)
self.layout().addItem(self.__iconLayoutItem)
channel_alignemnt = Qt.AlignLeft
self.layout().setAlignment(self.__iconLayoutItem, Qt.AlignCenter)
self.layout().setAlignment(self.__channelLayout,
Qt.AlignVCenter | channel_alignemnt)
if node is not None:
self.setSchemeNode(node)
def setIconSize(self, size):
"""
Set the icon size for the node.
"""
if size != self.__iconSize:
self.__iconSize = QSize(size)
if self.__icon:
self.__iconItem.setPixmap(self.__icon.pixmap(size))
self.__iconLayoutItem.updateGeometry()
def iconSize(self):
"""
Return the icon size.
"""
return QSize(self.__iconSize)
def setIcon(self, icon):
"""
Set the icon to display.
"""
if icon != self.__icon:
self.__icon = QIcon(icon)
self.__iconItem.setPixmap(icon.pixmap(self.iconSize()))
self.__iconLayoutItem.updateGeometry()
def icon(self):
"""
Return the icon.
"""
return QIcon(self.__icon)
def setSchemeNode(self, node):
"""
Set an instance of `SchemeNode`. The widget will be initialized
with its icon and channels.
"""
self.node = node
if self.__direction == Qt.LeftToRight:
channels = node.output_channels()
else:
channels = node.input_channels()
self.channels = channels
loader = icon_loader.from_description(node.description)
icon = loader.get(node.description.icon)
self.setIcon(icon)
#.........这里部分代码省略.........
示例2: ProbabilitiesItem
# 需要导入模块: from PyQt4.QtGui import QGraphicsPixmapItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPixmapItem import setPixmap [as 别名]
class ProbabilitiesItem(orangeqt.PlotItem):
"""
Displays class probabilities in the background
:param classifier: The classifier for which the probabilities are calculated
:type classifier: orange.P2NN
:param granularity: The size of individual cells
:type granularity: int
:param scale: The data scale factor
:type scale: float
:param spacing: The space between cells
:param spacing: int
:param rect: The rectangle into which to draw the probabilities. If unspecified, the entire plot is used.
:type rect: QRectF
"""
def __init__(self, classifier, granularity, scale, spacing, rect=None):
orangeqt.PlotItem.__init__(self)
self.classifier = classifier
self.rect = rect
self.granularity = granularity
self.scale = scale
self.spacing = spacing
self.pixmap_item = QGraphicsPixmapItem(self)
self.set_in_background(True)
self.setZValue(ProbabilitiesZValue)
def update_properties(self):
## Mostly copied from OWScatterPlotGraph
if not self.plot():
return
if not self.rect:
x, y = self.axes()
self.rect = self.plot().data_rect_for_axes(x, y)
s = self.graph_transform().mapRect(self.rect).size().toSize()
if not s.isValid():
return
rx = s.width()
ry = s.height()
rx -= rx % self.granularity
ry -= ry % self.granularity
p = self.graph_transform().map(QPointF(0, 0)) - self.graph_transform().map(self.rect.topLeft())
p = p.toPoint()
ox = p.x()
oy = -p.y()
if isinstance(self.classifier.classVar, ContinuousVariable):
imagebmp = orangeom.potentialsBitmap(self.classifier, rx, ry, ox, oy, self.granularity, self.scale)
palette = [qRgb(255.0 * i / 255.0, 255.0 * i / 255.0, 255 - (255.0 * i / 255.0)) for i in range(255)] + [
qRgb(255, 255, 255)
]
else:
imagebmp, nShades = orangeom.potentialsBitmap(
self.classifier, rx, ry, ox, oy, self.granularity, self.scale, self.spacing
)
palette = []
sortedClasses = get_variable_values_sorted(self.classifier.domain.classVar)
for cls in self.classifier.classVar.values:
color = self.plot().discPalette.getRGB(sortedClasses.index(cls))
towhite = [255 - c for c in color]
for s in range(nShades):
si = 1 - float(s) / nShades
palette.append(qRgb(*tuple([color[i] + towhite[i] * si for i in (0, 1, 2)])))
palette.extend([qRgb(255, 255, 255) for i in range(256 - len(palette))])
self.potentialsImage = QImage(imagebmp, rx, ry, QImage.Format_Indexed8)
self.potentialsImage.setColorTable(ColorPaletteDlg.signedPalette(palette) if qVersion() < "4.5" else palette)
self.potentialsImage.setNumColors(256)
self.pixmap_item.setPixmap(QPixmap.fromImage(self.potentialsImage))
self.pixmap_item.setPos(self.graph_transform().map(self.rect.bottomLeft()))
def data_rect(self):
return self.rect if self.rect else QRectF()