def _generate_indicators(self, **kwargs): # pylint: disable=unused-argument """ Paint arrow indicators of selected instructions and labels. """ scene = self.scene() for item in self._map_indicator_items: scene.removeItem(item) self._map_indicator_items.clear() for addr in list(self.disasm_view.infodock.selected_insns) + list( self.disasm_view.infodock.selected_labels): pos = self._get_pos_from_addr(addr) if pos is None: continue pos -= 1 # this is the top-left x coordinate of our arrow body (the rectangle) pen = QPen(Qt.yellow) brush = QBrush(Qt.yellow) item = QGraphicsRectItem(QRectF(pos, 0, 2, 10), parent=self) item.setPen(pen) item.setBrush(brush) item.setZValue(self.ZVALUE_INDICATOR) self._map_indicator_items.append(item) triangle = QPolygonF() triangle.append(QPointF(pos - 1, 10)) triangle.append(QPointF(pos + 3, 10)) triangle.append(QPointF(pos + 1, 12)) triangle.append(QPointF(pos - 1, 10)) item = QGraphicsPolygonItem(triangle, parent=self) item.setPen(pen) item.setBrush(brush) item.setZValue(self.ZVALUE_INDICATOR) self._map_indicator_items.append(item)
def getNewWindow(cls, targetImage=None, axeSize=500, layer=None, parent=None, curveType='quadric'): newWindow = graphicsToneForm(targetImage=targetImage, axeSize=axeSize, layer=layer, parent=parent, curveType=curveType) newWindow.setWindowTitle(layer.name) # init marker triangle = QPolygonF() s = 10 triangle.append(QPointF(-s, s)) triangle.append(QPointF(0, 0)) triangle.append(QPointF(s, s)) newWindow.inputMarker = QGraphicsPolygonItem(triangle) newWindow.scene().addItem(newWindow.inputMarker) newWindow.inputMarker.setBrush(QBrush(Qt.white)) return newWindow
print(f'Rect Pos: {rectItem.pos()}') textItem = QGraphicsSimpleTextItem("Foundation of Qt") scene.addItem(textItem) print(f'Text Pos: {textItem.pos()}') textItem.setPos(50, 0) print(f'Text Pos: {textItem.pos()}') ellipseItem = QGraphicsEllipseItem(QRectF(170, 20, 100, 75)) ellipseItem.setPen(QPen(Qt.darkBlue)) ellipseItem.setBrush(Qt.blue) scene.addItem(ellipseItem) points = [ QPointF(10, 10), QPointF(0, 90), QPointF(40, 70), QPointF(80, 110), QPointF(70, 20) ] polygonItem = QGraphicsPolygonItem(QPolygonF(points)) polygonItem.setPen(QPen(Qt.darkGreen)) polygonItem.setBrush(Qt.yellow) scene.addItem(polygonItem) view = QGraphicsView() view.setScene(scene) view.show() sys.exit(app.exec_())
def _create_line_indicator(self, addr, item_map, color=Qt.yellow, show_frontier=False, z=None, z_frontier=None): """ Generate a cursor at a given address. """ pos_x = self._get_pos_from_addr(addr) if pos_x is None: return pen = QPen(color) brush = QBrush(color) height = self.height tri_width = 7 tri_height = 4 pos_x = int(pos_x - tri_width / 2) # Center drawing center = pos_x + int(tri_width / 2) pos_y = 0 frontier_width = int(0.15 * max(self.width, self.height)) if show_frontier: # Draw frontier gradients r = QRectF(center - frontier_width, pos_y, frontier_width, height) bg = QLinearGradient(r.topLeft(), r.topRight()) color = Qt.red top_color = QColor(color) top_color.setAlpha(0) bg.setColorAt(0, top_color) bottom_color = QColor(color) bottom_color.setAlpha(180) bg.setColorAt(1, bottom_color) i = QGraphicsRectItem(r, parent=self) i.setPen(Qt.NoPen) i.setBrush(bg) if z_frontier is not None: i.setZValue(z_frontier) item_map.append(i) r = QRectF(center, pos_y, frontier_width, height) bg = QLinearGradient(r.topLeft(), r.topRight()) color = Qt.blue top_color = QColor(color) bg.setColorAt(0, top_color) bottom_color = QColor(color) bottom_color.setAlpha(0) bg.setColorAt(1, bottom_color) i = QGraphicsRectItem(r, parent=self) i.setPen(Qt.NoPen) i.setBrush(bg) if z_frontier is not None: i.setZValue(z_frontier) item_map.append(i) # Draw line i = QGraphicsLineItem(center, 0, center, height, parent=self) i.setPen(pen) if z is not None: i.setZValue(z) item_map.append(i) # Draw top and bottom triangles t = QPolygonF() t.append(QPointF(pos_x, pos_y)) t.append(QPointF(pos_x + tri_width - 1, pos_y)) t.append(QPointF(center, pos_y + tri_height - 1)) t.append(QPointF(pos_x, pos_y)) pos_y += height - 1 b = QPolygonF() b.append(QPointF(pos_x, pos_y)) b.append(QPointF(center, pos_y - tri_height + 1)) b.append(QPointF(pos_x + tri_width - 1, pos_y)) b.append(QPointF(pos_x, pos_y)) for i in [QGraphicsPolygonItem(t, parent=self), QGraphicsPolygonItem(b, parent=self)]: i.setPen(pen) i.setBrush(brush) if z is not None: i.setZValue(z) item_map.append(i)