def create_qr_scene(self, scene, qr_pixel_map, qr_text, backgound_pixmap) : pixmap_item = QGraphicsPixmapItem(qr_pixel_map) pixmap_item.setY(100) pixmap_item.setX(100) background_item = QGraphicsPixmapItem(backgound_pixmap) url_item = QGraphicsTextItem(qr_text) url_item.setFont(QFont('Arial', 50)) url_item.setTextWidth(820) url_item.setY(450) url_item.setX(1150) url_item.setZValue(1) pixmap_item.setZValue(1) background_item.setZValue(-1) scene.addItem(pixmap_item) scene.addItem(url_item) scene.addItem(background_item) return scene
def __init__(self, parent): super(ImageSegmenterView, self).__init__(parent) self._zoom = 0 self.empty = True self._scene = QGraphicsScene(self) self._photo = QGraphicsPixmapItem() self.image_hidden = False self._seglayer = QGraphicsPixmapItem() self._seglayer.setOpacity(0.5) self._scene.addItem(self._photo) self._scene.addItem(self._seglayer) self.setScene(self._scene) self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) self.setResizeAnchor(QGraphicsView.AnchorUnderMouse) # self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) # self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setBackgroundBrush(QBrush(QtCore.Qt.darkGray)) self.setFrameShape(QFrame.NoFrame) self.seg_image = None self.start = False self.prev_point = None self.painter = None self.segmenter_pen = QPen(QtCore.Qt.green, 30, QtCore.Qt.SolidLine) self.segmenter_pen.setCapStyle(QtCore.Qt.RoundCap) self.segmenter_pen.setJoinStyle(QtCore.Qt.RoundJoin) self.erase = False self.changed = False self.history = collections.deque(maxlen=10) self.future = collections.deque(maxlen=10)
def __init__(self, parent=None, view=None): QGraphicsScene.__init__(self, parent) self.undoStack = QUndoStack(self) # super(Scene, self).__init__(parent) self.view = view self.imgPosibleConnectH = QGraphicsPixmapItem( os.path.join(PATHBLOCKSIMG, "ConnectH.png")) super(Scene, self).addItem(self.imgPosibleConnectH) self.imgPosibleConnectH.setVisible(False) self.imgPosibleConnectV = QGraphicsPixmapItem( os.path.join(PATHBLOCKSIMG, "ConnectV.png")) super(Scene, self).addItem(self.imgPosibleConnectV) self.imgPosibleConnectV.setVisible(False) self.oldPos = None self.createActions()
def cellClicked(self): print('cell is clicked') self.tableRow, self.tableColumn = self.table.currentRow( ), self.table.currentColumn() print('row, column', self.tableRow, self.tableColumn) self.scene_class.spreadsheet.control.humancombo.setCurrentIndex( self.tableRow) self.scene_class.spreadsheet.control.jointcombo.setCurrentIndex( self.tableColumn) self.Show_Image() coord = self.table.currentItem().text() print('coord is ', coord) color = QColor() color.setRgb(255, 0, 0, a=255) if coord: jointx, jointy = coord.split(',') jointx, jointy = int(jointx), int(jointy) for x in range(jointx - 6, jointx + 7): self.Image.setPixelColor(x, jointy - 1, color) self.Image.setPixelColor(x, jointy, color) self.Image.setPixelColor(x, jointy + 1, color) for y in range(jointy - 6, jointy + 7): self.Image.setPixelColor(jointx - 1, y, color) self.Image.setPixelColor(jointx, y, color) self.Image.setPixelColor(jointx + 1, y, color) self.image_item = QGraphicsPixmapItem(QPixmap(self.Image)) self.scene().addItem(self.image_item)
def plot(self, filename): image = QPixmap() image.load(filename) item = QGraphicsPixmapItem(image) scene = QGraphicsScene() scene.addItem(item) self.ui.graphicsView.setScene(scene)
def setup_scene(self, img: Image): #if img.mode != "RGB": #img = img.convert("RGB") self.image = img scene = CanvasGraphicsScene() self.setScene(scene) #scene固有の初期化 qtimg = ImageQt(self.image) pixmap = QPixmap.fromImage(qtimg).copy() pixmap_item = QGraphicsPixmapItem(pixmap) self.scene().addItem(pixmap_item) pixmap_item.setPos(0, 0) self.rect_item = QGraphicsRectItem(0, 0, 200, 200) self.rect_item.setPen(QPen(QtCore.Qt.blue, 3)) self.rect_item.hide() self.scene().addItem(self.rect_item) self.frame_rect_item = QGraphicsRectItem(0, 0, self.image.width - 3, self.image.height - 3) self.frame_rect_item.setPen(QPen(QtCore.Qt.red, 5)) self.scene().addItem(self.frame_rect_item) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) img = self.image self.setSceneRect(0, 0, img.width, img.height) self.setFixedSize(img.width, img.height) self._dragging = False pass
def main(): app = QtWidgets.QApplication(sys.argv) image = QImage("wallpaper.jpg") item = QGraphicsPixmapItem(QPixmap.fromImage(image)) main_window = CroppingImageWidget(item) main_window.show() sys.exit(app.exec_())
def paintTile(self, tilemaps, current_tilemap, x, y, tilemap_x, tilemap_y, tilemap_w=32, tilemap_h=32): self._current_tilemap = current_tilemap # Position and dimension of tile in the tile map. tile_item = None tile_from_map = (tilemap_x, tilemap_y) clip_space = QRect(tilemap_x, tilemap_y, tilemap_w, tilemap_h) tile = tilemaps[self._current_tilemap].copy(clip_space) tile_pos = self.findTilePos(x, y) ''' if tile_pos in self._on_canvas.keys(): self._on_canvas[tile_pos] = tile_from_map self._scene.removeItem(self._tile_items[tile_pos]) else: self._on_canvas[tile_pos] = tile_from_map ''' if tile_pos in self._layers[self._current_layer][LayerKeys.ITEM_LIST]: self._layers[self._current_layer][LayerKeys.ITEM_GROUP].removeFromGroup(self._layers[self._current_layer][LayerKeys.ITEM_LIST][tile_pos]) self._scene.removeItem(self._layers[self._current_layer][LayerKeys.ITEM_LIST][tile_pos]) self._layers[self._current_layer][LayerKeys.ITEM_TMAP_POS_LIST][tile_pos] = tile_from_map #self._tile_items[tile_pos] = self._scene.addPixmap(tile) #self._tile_items[tile_pos].setPos(tile_pos[0], tile_pos[1]) tile_item = QGraphicsPixmapItem(tile) tile_item.setPos(tile_pos[0], tile_pos[1]) self._layers[self._current_layer][LayerKeys.ITEM_GROUP].addToGroup(tile_item) self._layers[self._current_layer][LayerKeys.ITEM_LIST][tile_pos] = tile_item
def refreshImage(self, i, j): currentItem = self.itemAt(self.xFromCol(j), self.yFromRow(i), QTransform()) if currentItem != 0 and currentItem.data(0) == 777: currentItem = None filename = self.getPieceFilename(self.board[i][j]) if filename == "": return y = self.nPieceWidth * i x = self.nPieceWidth * j item = QGraphicsPixmapItem(QPixmap(filename)) colorize = QGraphicsColorizeEffect() if self.board[i][j].color() == pieceColor.White: if self.threatPiece[i][j]: colorize.setColor(self.cLightPieceColorThreat) else: colorize.setColor(self.cLightPieceColor) else: if self.threatPiece[i][j]: colorize.setColor(self.cDarkPieceColorThreat) else: colorize.setColor(self.cDarkPieceColor) item.setGraphicsEffect(colorize) item.setCacheMode(QGraphicsItem.NoCache) # needed for proper rendering item.setData(0, 777) self.addItem(item) item.setPos(x, y)
def update_pixmap_in_graphics_viewer(self, pixmap: QPixmap): self.pixmap = pixmap scene = QGraphicsScene() pixmap_item = QGraphicsPixmapItem(self.pixmap) scene.addItem(pixmap_item) self.gaphices_viewer.setScene(scene)
def init(self): self.piiPath = str() self._model = {'background': str()} self._isPanning = False self._isZooming = False self._mousePressed = False self._scene = QGraphicsScene() self._scene.selectionChanged.connect(self.update_node_settings) self._backgroundNode = QGraphicsPixmapItem() self._scene.addItem(self._backgroundNode) self._orderSelected = list() self._lastPos = QPoint(0, 0) self.editMode = False self._namespace = str() self._dragMulti = list() self._defaultColor = QColor(255, 255, 255) self._defaultTextColor = QColor(0, 0, 0) self._defaultTextSize = 20 self._defaultText = "New Node" self.workHight = 2160 self.workWidth = 4096 self.setScene(self._scene) self.setContextMenuPolicy(Qt.CustomContextMenu) self.setBackgroundImage(str())
def init(self): brush = QBrush() brush.setColor(Qt.black) brush.setStyle(Qt.SolidPattern) self.setBackgroundBrush(brush) font = QFont() font.setPointSize(20) font.setBold(True) self.one_play_text_item.setPlainText('One Player') self.two_plays_text_item.setPlainText('Two Players') self.one_play_text_item.setDefaultTextColor(Qt.white) self.two_plays_text_item.setDefaultTextColor(Qt.white) self.one_play_text_item.setFont(font) self.two_plays_text_item.setFont(font) self.one_play_text_item.setX(300) self.two_plays_text_item.setX(300) self.one_play_text_item.setY(self.y_list[0]) self.two_plays_text_item.setY(self.y_list[1]) self.addItem(self.one_play_text_item) self.addItem(self.two_plays_text_item) png = QPixmap() png.load('../images/%s' % TankType.PLAYER_ONE.pic) png = png.scaled(25, 25) self.indicator_item = QGraphicsPixmapItem(png) self.indicator_item.setRotation(90) self.indicator_item.setX(260) self.indicator_item.setY(self.y_list[self.selected] + 8) self.addItem(self.indicator_item)
def __init__(self, size=100, border=20, parentItem=None): super().__init__(size=size, parentItem=parentItem) # brightness sliders self.brightnessSliderHeight = 20 self.brightnessSliderWidth = size #+ 2 * border px = QPixmap(self.brightnessSliderWidth, self.brightnessSliderHeight) px.fill(Qt.gray) self.brightnessSlider = QGraphicsPixmapItem(px, parent=self) self.brightnessSlider.setPos(0, size + 20) # brightnessSlider handles self.brightnessThr0 = activeRsMarker.fromTriangle( parent=self.brightnessSlider, role='min') self.brightnessThr0.setMoveRange( QRectF(0.0, self.brightnessThr0.size, self.brightnessSlider.pixmap().width(), 0.0)) self.brightnessThr0.setPos( 0, self.brightnessSlider.pixmap().height() - self.brightnessThr0.size) self.brightnessThr0.val = 0.0 self.brightnessThr1 = activeRsMarker.fromTriangle( parent=self.brightnessSlider, role='max') self.brightnessThr1.setMoveRange( QRectF(0.0, self.brightnessThr0.size, self.brightnessSlider.pixmap().width(), 0.0)) self.brightnessThr1.setPos( self.brightnessSlider.pixmap().width(), self.brightnessSlider.pixmap().height() - self.brightnessThr0.size) self.brightnessThr1.val = 1.0
def __init__(self, parent=None, image=None): super(ImageVisualiseScene, self).__init__(parent) if image and isinstance(image, Image): self._image = image else: self._image = Image() self.pixmap_item = QGraphicsPixmapItem() self.addItem(self.pixmap_item)
def overlay_image(self, img: bytes, x: int, y: int, width: int, timeout: int): img = self.get_qimage(img, width) gfx = QGraphicsPixmapItem(QPixmap.fromImage(img)) gfx.setPos(x, y) self._finalize_gfx(gfx, timeout)
def create_start_scene(self, scene, qr_pixel_map): text_item = QGraphicsTextItem("Wilkommen zur Photobox bitte den Start Button Drücken") text_item.setFont(QFont('Arial', 50)) pixmap_item = QGraphicsPixmapItem(qr_pixel_map) scene.addItem(pixmap_item) return scene
def clear_scene(self): ''' Clear the scene. ''' self._orderSelected = list() self._scene.clear() self._backgroundNode = QGraphicsPixmapItem() self._scene.addItem(self._backgroundNode) self.reset_view()
def map_View_Update(self, msg): try: item = QGraphicsPixmapItem(msg) scene = QGraphicsScene() scene.addItem(item) self.ui.Map_View.setScene(scene) self.ui.Map_View.show() except: pass
def view_Clear(self): try: clear = QPixmap(1, 1) clear.fill(QColor("white")) clear = QGraphicsPixmapItem(clear) scene = QGraphicsScene() scene.addItem(clear) return scene except: pass
def __init__(self): QMainWindow.__init__(self) self.image = QPixmap("sec_shield.png") self.item = QGraphicsPixmapItem(self.image) self.scene = QGraphicsScene() self.scene.addItem(self.item) self.view = QGraphicsView() self.view.setScene(self.scene) self.view.show()
def __init__(self, parent=None): super().__init__(parent) self.Imagelist = glob.glob('IMAGE/*.jpg') #print('読み込まれた画像のリストは', self.Imagelist) self.image_item = QGraphicsPixmapItem(QPixmap(QImage(self.Imagelist[0]))) self.height, self.width, _ = (cv2.imread(self.Imagelist[0])).shape self.current = self.Imagelist[0] self.addItem(self.image_item) self.setBackgroundBrush(QBrush(Qt.black))
def __init__(self): super().__init__() self._tag_brushes = [] self._tag_brushes.append(QBrush(QColor(0, 0, 0, 0))) self._tag_brushes.append(QBrush(QColor(255, 0, 0, 90))) self._image_item = QGraphicsPixmapItem() self._create_default_scene() self.setScene(self._scene)
def set_image_on_viewer(self): # Delete existing image item if len(self.imgs_pixmap) != 0: for item in self.imgs_pixmap: self.scene.removeItem(item) self.scene.clear_contents() self.imgs_pixmap.clear() self.imgs.clear() # load original image self.org_qimg = QImage(self.org_img_file_path) self.org_pixmap = QPixmap.fromImage(self.org_qimg) org_img_size = self.org_qimg.size() self.org_img_width = org_img_size.width() self.org_img_height = org_img_size.height() # Set layer image self.layer_qimg = QImage(self.org_img_width, self.org_img_height, QImage.Format_RGBA8888) self.layer_qimg.fill(QColor(0, 0, 0, self.layer_alpha)) self.layer_pixmap = QPixmap.fromImage(self.layer_qimg) self.imgs.append(self.org_qimg) self.imgs.append(self.layer_qimg) # Set image to scene self.imgs_pixmap.append(QGraphicsPixmapItem(self.org_pixmap)) self.scene.addItem(self.imgs_pixmap[-1]) self.imgs_pixmap.append(QGraphicsPixmapItem(self.layer_pixmap)) self.scene.addItem(self.imgs_pixmap[-1]) self.scene.set_img_contents(self.imgs) # Set scene to graphics view self.graphics_view.setScene(self.scene) self.graphics_view.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.show()
def __init__(self, name='node', parent=None): super(NodeItem, self).__init__(name, parent) pixmap = QtGui.QPixmap(ICON_NODE_BASE) if pixmap.size().height() > NODE_ICON_SIZE: pixmap = pixmap.scaledToHeight(NODE_ICON_SIZE, QtCore.Qt.SmoothTransformation) self._properties['icon'] = ICON_NODE_BASE self._icon_item = QGraphicsPixmapItem(pixmap, self) self._icon_item.setTransformationMode(QtCore.Qt.SmoothTransformation) self._text_item = QGraphicsTextItem(self.name, self) self._x_item = XDisabledItem(self, 'DISABLED') self._input_items = {} self._output_items = {} self._widgets = {}
def __init__(self, parent): super(PhotoViewer, self).__init__(parent) self._zoom = 0 self._empty = True self._scene = QGraphicsScene(self) self._photo = QGraphicsPixmapItem() self._scene.addItem(self._photo) self.setScene(self._scene) self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) self.setResizeAnchor(QGraphicsView.AnchorUnderMouse) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setBackgroundBrush(QBrush(QColor(30, 30, 30))) self.setFrameShape(QFrame.NoFrame)
def __init__(self, name: str, id: int, optionsSet: bool, inputs=None, parent: QtWidgets.QGraphicsItem = None, output: bool = True): """Create an instance of this class """ super().__init__(parent) if inputs is None: inputs = list() self._name = name self._id = id # Set font used for label (operation name) self._title_font = QtGui.QFont("Arial", 14) # Compute size of label to display self._width = max(150, GraphNode.__headerSize(self._name, self._title_font).width()) self._height = 130 self._outline = 6 self._slot_radius = 10 self._label_height = 34 self._bbox = None # cache container self._round_slot = None self._rect_slot = None self._hover_slot = False self.setFlags(QtWidgets.QGraphicsItem.ItemIsMovable | QtWidgets.QGraphicsItem.ItemIsSelectable) self.setAcceptHoverEvents(False) # Build output slot self._output = NodeSlot(name="out", parent=self, family=NodeSlot.OUTPUT) if output else None # Build input slots self._inputs = [] for i, slot_name in enumerate(inputs): an_input = NodeSlot(name=slot_name, parent=self, position=i) self._inputs.append(an_input) self._status = NodeStatus.NONE self._status_slot = NodeSlot(name=None, parent=self, family=NodeSlot.STATUS) # Update internal containers self._update() # Node options indicator self._optionsSet: bool = None self._optionsIndicator: QGraphicsPixmapItem = QGraphicsPixmapItem(self) self.setOptionsIndicator(optionsSet) center = self.boundingRect().center() offsetW = self._optionsIndicator.boundingRect().width() // 2 offsetH = self._optionsIndicator.boundingRect().height() // 2 self._optionsIndicator.setPos(center.x() - offsetW, center.y() - offsetH // 2)
def __init__(self): super(self.__class__, self).__init__() self.bookId = "" self.epsId = 0 self.curIndex = 0 self.gridLayout = QtWidgets.QGridLayout(self) self.setWindowTitle("图片查看") self.setWindowModality(QtCore.Qt.ApplicationModal) self.resize(402, 509) # self.setWindowFlags(Qt.FramelessWindowHint) self.graphicsView = QtWidgets.QGraphicsView(self) self.graphicsView.setFrameStyle(QFrame.NoFrame) self.graphicsView.setObjectName("graphicsView") self.graphicsView.setBackgroundBrush(QColor(Qt.white)) self.graphicsView.setCursor(Qt.OpenHandCursor) self.graphicsView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.graphicsView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.graphicsView.setRenderHints(QPainter.Antialiasing | QPainter.HighQualityAntialiasing | QPainter.SmoothPixmapTransform) self.graphicsView.setCacheMode(self.graphicsView.CacheBackground) self.graphicsView.setViewportUpdateMode( self.graphicsView.SmartViewportUpdate) self.graphicsItem = QGraphicsPixmapItem() self.graphicsItem.setFlags(QGraphicsPixmapItem.ItemIsFocusable | QGraphicsPixmapItem.ItemIsMovable) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.CopyPicture) self.graphicsScene = QGraphicsScene(self) # 场景 self.graphicsView.setScene(self.graphicsScene) self.graphicsScene.addItem(self.graphicsItem) self.graphicsView.setMinimumSize(10, 10) self.pixMap = QPixmap("加载中") self.graphicsItem.setPixmap(self.pixMap) # self.radioButton.setChecked(True) self.isStripModel = False # self.radioButton.installEventFilter(self) # self.radioButton_2.installEventFilter(self) self.graphicsView.installEventFilter(self) self.graphicsView.setWindowFlag(Qt.FramelessWindowHint) self.gridLayout.addWidget(self.graphicsView) self._delta = 0.1 self.scaleCnt = 0
def initialize_map(self): self.grahpicsitem = [] self.scene.clear() for i in self.hex: if self.game.map[i[0]][i[1]] == " ": cell = QGraphicsPixmapItem(self.grass) cell.setPos(QPointF(i[1] * 10, i[0] * 10)) self.grahpicsitem.append(cell) self.scene.addItem(cell) elif self.game.map[i[0]][i[1]] == "#": cell = QGraphicsPixmapItem(self.black) cell.setPos(QPointF(i[1] * 10, i[0] * 10)) self.grahpicsitem.append(cell) self.scene.addItem(cell) elif self.game.map[i[0]][i[1]] == "+": cell = QGraphicsPixmapItem(self.white) cell.setPos(QPointF(i[1] * 10, i[0] * 10)) self.grahpicsitem.append(cell) self.scene.addItem(cell) if self.game.map[i[0]][i[1]] == "@": cell = QGraphicsPixmapItem(self.apple) cell.setPos(QPointF(i[1] * 10, i[0] * 10)) self.grahpicsitem.append(cell) self.scene.addItem(cell)
def __init__(self, parent=None, left=False): super().__init__(parent) self._is_left = left self._portrait_textures: Optional[Dict[str, Texture]] = None self._portrait_image: Optional[Image] = None self._blush_image: Optional[Image] = None self._sweat_image: Optional[Image] = None self._blush_x = None self._blush_y = None self._sweat_x = None self._sweat_y = None self._portrait_view = QGraphicsPixmapItem() self.addToGroup(self._portrait_view)
def load_image(self, abspath): if self._gfx_item: self._gfx_scene.removeItem(self._gfx_item) self.gfx_slide.viewport().update() self.gfx_slide.centerOn(0, 0) self._gfx_item = QGraphicsPixmapItem() img = QImage(abspath) pixmap = QPixmap(img) pixmap = pixmap.scaled(self.gfx_slide.size(), QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) self._control_widget_proxy.setX((pixmap.width() / 2) - ( self._control_widget_proxy.size().width() / 2)) self._gfx_item.setPixmap(pixmap) self._gfx_scene.addItem(self._gfx_item) self._gfx_scene.setSceneRect(self._gfx_item.sceneBoundingRect())