本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsPixmapItem方法的典型用法代码示例。如果您正苦于以下问题:Python QtWidgets.QGraphicsPixmapItem方法的具体用法?Python QtWidgets.QGraphicsPixmapItem怎么用?Python QtWidgets.QGraphicsPixmapItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets
的用法示例。
在下文中一共展示了QtWidgets.QGraphicsPixmapItem方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_image
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPixmapItem [as 别名]
def load_image(self):
""" Add image to scene if it exists. """
source = self.app.project_path + self.file_['mediapath']
image = QtGui.QImage(source)
if image.isNull():
QtWidgets.QMessageBox.warning(None, _("Image Error"), _("Cannot open: ") + source)
self.close()
logger.warning("Cannot open image: " + source)
return
items = list(self.scene.items())
for i in range(items.__len__()):
self.scene.removeItem(items[i])
self.setWindowTitle(_("Image: ") + self.file_['name'])
self.ui.pushButton_memo.setEnabled(True)
self.pixmap = QtGui.QPixmap.fromImage(image)
pixmap_item = QtWidgets.QGraphicsPixmapItem(QtGui.QPixmap.fromImage(image))
pixmap_item.setPos(0, 0)
self.scene.setSceneRect(QtCore.QRectF(0, 0, self.pixmap.width(), self.pixmap.height()))
self.scene.addItem(pixmap_item)
self.ui.horizontalSlider.setValue(99)
self.draw_coded_areas()
示例2: scene_context_menu
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPixmapItem [as 别名]
def scene_context_menu(self, pos):
""" Scene context menu for unmarking coded areas and adding memos. """
# outside image area, no context menu
for item in self.scene.items():
if type(item) == QtWidgets.QGraphicsPixmapItem:
if pos.x() > item.boundingRect().width() or pos.y() > item.boundingRect().height():
self.selection = None
return
menu = QtWidgets.QMenu()
menu.addAction(_('Memo'))
menu.addAction(_('Unmark'))
global_pos = QtGui.QCursor.pos()
item = self.find_coded_areas_for_pos(pos)
# no coded area item in this mouse position
if item is None:
return
action = menu.exec_(global_pos)
if action is None:
return
if action.text() == _('Memo'):
self.coded_area_memo(item)
if action.text() == _('Unmark'):
self.unmark(item)
示例3: blurPixmap
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPixmapItem [as 别名]
def blurPixmap(pixmap, radius):
effect = QGraphicsBlurEffect()
effect.setBlurRadius(radius)
buffer = QPixmap(pixmap)
item = QGraphicsPixmapItem(buffer)
item.setGraphicsEffect(effect)
output = QPixmap(pixmap.width(), pixmap.height())
painter = QtGui.QPainter(output)
scene = QtWidgets.QGraphicsScene()
view = QtWidgets.QGraphicsView(scene)
scene.addItem(item)
scene.render(painter)
return output
示例4: pixmap
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPixmapItem [as 别名]
def pixmap(self, value: QPixmap):
self._pixmap = value
self._pixmap = QGraphicsPixmapItem()
self._pixmap.setPixmap(value)
size = 300
w = value.width()
h = value.height()
scale = size / w
new_w, new_h = w * scale, h * scale
self._pixmap.setOffset(-value.width() / 2, -value.height() / 2)
self._pixmap.setTransformationMode(QtCore.Qt.SmoothTransformation)
self._scene.addItem(self._pixmap)
self.scale(scale, scale)
示例5: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPixmapItem [as 别名]
def __init__(self, parent=None):
super(AnnotationScene, self).__init__(parent)
self.image_item = QtWidgets.QGraphicsPixmapItem()
self.image_item.setCursor(QtGui.QCursor(QtCore.Qt.CrossCursor))
self.addItem(self.image_item)
self.current_instruction = Instructions.No_Instruction
示例6: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPixmapItem [as 别名]
def __init__(self, view):
self._view = view
self._scene = QtWidgets.QGraphicsScene(self._view)
self._view.setScene(self._scene)
self._canvas = QtWidgets.QGraphicsPixmapItem()
self._scene.addItem(self._canvas)
self._zoom = 0
self._view.wheelEvent = self.zoomWheelEvent
# zoom wheel
示例7: show_full_scene
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPixmapItem [as 别名]
def show_full_scene(self):
for item in self.scene.items():
if isinstance(item, QGraphicsPixmapItem):
self.scene.removeItem(item)
x_pos = 0
for image in self.spectrogram.create_image_segments():
item = self.scene.addPixmap(QPixmap.fromImage(image))
item.setPos(x_pos, 0)
x_pos += image.width()
QApplication.instance().processEvents()
# Estimated time_bins from update_scene_rect may be too many for small signals so we update the scene rect
# after we know how wide the spectrogram actually is
self.scene.setSceneRect(0, 0, x_pos, self.spectrogram.freq_bins)
示例8: change_scale
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPixmapItem [as 别名]
def change_scale(self):
""" Resize image. Triggered by user change in slider.
Also called by unmark, as all items need to be redrawn. """
if self.pixmap is None:
return
self.scale = (self.ui.horizontalSlider.value() + 1) / 100
height = self.scale * self.pixmap.height()
pixmap = self.pixmap.scaledToHeight(height, QtCore.Qt.FastTransformation)
pixmap_item = QtWidgets.QGraphicsPixmapItem(pixmap)
pixmap_item.setPos(0, 0)
self.scene.clear()
self.scene.addItem(pixmap_item)
self.draw_coded_areas()
示例9: code_area
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPixmapItem [as 别名]
def code_area(self, p1):
""" Created coded area coordinates from mouse release.
The point and width and height mush be based on the original image size,
so add in scale factor. """
code_ = self.ui.treeWidget.currentItem()
if code_ is None:
return
if code_.text(1)[0:3] == 'cat':
return
cid = code_.text(1)[4:]
x = self.selection.x()
y = self.selection.y()
#print("x", x, "y", y, "scale", self.scale)
width = p1.x() - x
height = p1.y() - y
if width < 0:
x = x + width
width = abs(width)
if height < 0:
y = y + height
height = abs(height)
#print("SCALED x", x, "y", y, "w", width, "h", height)
# outside image area, do not code
for item in self.scene.items():
if type(item) == QtWidgets.QGraphicsPixmapItem:
if x + width > item.boundingRect().width() or y + height > item.boundingRect().height():
self.selection = None
return
x_unscaled = x / self.scale
y_unscaled = y / self.scale
width_unscaled = width / self.scale
height_unscaled = height / self.scale
#print("UNSCALED x", x, "y", y, "w", width, "h", height)
item = {'imid': None, 'id': self.file_['id'], 'x1': x_unscaled, 'y1': y_unscaled,
'width': width_unscaled, 'height':height_unscaled, 'owner': self.app.settings['codername'],
'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'cid': cid,'memo': ''}
cur = self.app.conn.cursor()
cur.execute("insert into code_image (id,x1,y1,width,height,cid,memo,date,owner) values(?,?,?,?,?,?,?,?,?)"
, (item['id'], item['x1'], item['y1'], item['width'], item['height'], cid, item['memo'],
item['date'],item['owner']))
self.app.conn.commit()
cur.execute("select last_insert_rowid()")
imid = cur.fetchone()[0]
item['imid'] = imid
self.code_areas.append(item)
rect_item = QtWidgets.QGraphicsRectItem(x, y, width, height)
color = None
for i in range(0, len(self.codes)):
if self.codes[i]['cid'] == int(cid):
color = QtGui.QColor(self.codes[i]['color'])
if color is None:
print("ERROR")
return
rect_item.setPen(QtGui.QPen(color, 2, QtCore.Qt.DashLine))
rect_item.setToolTip(code_.text(0))
self.scene.addItem(rect_item)
self.selection = None