def setPhoto(self, pixmap=None): self._zoom = 0 if pixmap and not pixmap.isNull(): self._empty = False self.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) self._photo.setPixmap(pixmap) else: self._empty = True self.setDragMode(QtWidgets.QGraphicsView.NoDrag) self._photo.setPixmap(QtGui.QPixmap()) self.fitInView()
def __init__(self, parent=None): super(RomanSpinBox, self).__init__(parent) regex = QtCore.QRegularExpression( r"^M?M?M?(?:CM|CD|D?C?C?C?)" r"(?:XC|XL|L?X?X?X?)(?:IX|IV|V?I?I?I?)$", QtCore.QRegularExpression.CaseInsensitiveOption, ) self.validator = QtGui.QRegularExpressionValidator(regex, self) self.setRange(1, 3999) self.connect(self.lineEdit(), QtCore.SIGNAL("textEdited(QString)"), self.fixCase)
def init_color_isod(self): """ Create a list containing the colors for each isodose. :return: Dictionary where the key is the percentage of isodose and the value a QColor object. """ roi_color = { 107: QtGui.QColor(131, 0, 0), 105: QtGui.QColor(185, 0, 0), 100: QtGui.QColor(255, 46, 0), 95: QtGui.QColor(255, 161, 0), 90: QtGui.QColor(253, 255, 0), 80: QtGui.QColor(0, 255, 0), 70: QtGui.QColor(0, 143, 0), 60: QtGui.QColor(0, 255, 255), 30: QtGui.QColor(33, 0, 255), 10: QtGui.QColor(11, 0, 134) } return roi_color
def init_gui(self): self._init_sizing(width=self.width) check_box = qtw.QCheckBox() check_box.setChecked(self.state.show) check_box.stateChanged.connect(self.change_state) self._init_layout(["", check_box, ""], is_vertical=False, margins=(3, 3, 3, 3)) self._init_palette({qtg.QPalette.Window: qtg.QColor("#C5FFFD")})
def drawOutline(self, qp): circle_pen = QtGui.QPen( self._palette.color(QtGui.QPalette.Active, QtGui.QPalette.Midlight)) circle_pen.setWidth(8) qp.setBrush( self._palette.brush(QtGui.QPalette.Active, QtGui.QPalette.Mid)) qp.setPen(circle_pen) qp.drawEllipse(self._square)
def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) self.setFixedSize(200, 120) self.quit = QtWidgets.QPushButton("Quit", self) self.quit.setGeometry(62, 40, 75, 30) self.quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold)) self.connect(self.quit, QtCore.SIGNAL("clicked()"), qApp, QtCore.SLOT("quit()"))
def onPreview(self): printer = QtPrintSupport.QPrinter( QtPrintSupport.QPrinter.HighResolution) layout = QtGui.QPageLayout() layout.setOrientation(QtGui.QPageLayout.Landscape) layout.setPageSize(QtGui.QPageSize.A3) printer.setPageLayout(layout) preview = QtPrintSupport.QPrintPreviewDialog(printer, self.parent) preview.paintRequested.connect(self.handlePaintRequest) preview.exec()
def itemChange(self, change, value): if change == QtWidgets.QGraphicsItem.ItemSelectedHasChanged: pen = self.pen() pen.setColor( QtGui.QColor(0, 255, 0, 255) if self.isSelected() else QtGui. QColor(0, 0, 0, 80)) self.setPen(pen) self.setZValue(self.zValue() + 1 if self.isSelected() else self.zValue() - 1) return super(EffectItem, self).itemChange(change, value)
def makeSplineMarkers(self): """Create marker for polygon contour""" self.splineMarkers = list() for x, y in zip(*self.spline_data[0]): # put airfoil contour points as graphicsitem splinemarker = gic.GraphicsCollection() splinemarker.pen.setColor(QtGui.QColor(60, 60, 80, 255)) splinemarker.brush.setColor(QtGui.QColor(203, 250, 72, 255)) splinemarker.pen.setWidthF(1.6) # no pen thickness change when zoomed splinemarker.pen.setCosmetic(True) splinemarker.Circle(x, y, 0.004) splineMarkerItem = GraphicsItem.GraphicsItem(splinemarker) self.splineMarkers.append(splineMarkerItem)
def __init__(self, part_id=None, *args, **kwargs): super(Thumb, self).__init__(*args, **kwargs) part_id = part_id or "" icon_path = ":{}".format(part_id) if QtCore.QFile.exists(icon_path): pixmap = QtGui.QPixmap(icon_path) scaled = pixmap.scaled(THUMB_SIZE, THUMB_SIZE, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) self.setPixmap(scaled) self.setMinimumSize(QtCore.QSize(THUMB_SIZE, THUMB_SIZE)) self.setMaximumSize(QtCore.QSize(THUMB_SIZE, THUMB_SIZE)) self.setAlignment(QtCore.Qt.AlignCenter)
def showNextPiece(self): if self.nextPieceLabel is not None: return dx = self.nextPiece.maxX() - self.nextPiece.minX() + 1 dy = self.nextPiece.maxY() - self.nextPiece.minY() + 1 pixmap = QtGui.QPixmap(dx * self.squareWidth(), dy * self.squareHeight()) painter = QtGui.QPainter(pixmap) painter.fillRect(pixmap.rect(), self.nextPieceLabel.palette().background()) for int in range(4): x = self.nextPiece.x(i) - self.nextPiece.minX() y = self.nextPiece.y(i) - self.nextPiece.minY() self.drawSquare(painter, x * self.squareWidth(), y * self.squareHeight(), self.nextPiece.shape()) self.nextPieceLabel.setPixmap(pixmap)
def test_save_image_in_tempfolder(): logger = logging.getLogger(__name__).root logger.setLevel("DEBUG") image = QtGui.QImage(20, 20, QtGui.QImage.Format.Format_RGB32) utils.save_image_in_tempfolder(image, postfix="unittest") png_files = (Path(tempfile.gettempdir()) / "normcap").glob("*.png") png_files = sorted(png_files, key=os.path.getmtime, reverse=True) assert "unittest" in str(list(png_files)[0])
def paint(self, painter, option, widget): painter.setPen(QtCore.Qt.NoPen) painter.setBrush(QtCore.Qt.darkGray) painter.drawEllipse(-7, -7, 20, 20) gradient = QtGui.QRadialGradient(-3, -3, 10) if option.state & QtWidgets.QStyle.State_Sunken: gradient.setCenter(3, 3) gradient.setFocalPoint(3, 3) gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.yellow).lighter(120)) gradient.setColorAt( 0, QtGui.QColor(QtCore.Qt.darkYellow).lighter(120)) else: gradient.setColorAt(0, QtCore.Qt.yellow) gradient.setColorAt(1, QtCore.Qt.darkYellow) painter.setBrush(QtGui.QBrush(gradient)) painter.setPen(QtGui.QPen(QtCore.Qt.black, 0)) painter.drawEllipse(-10, -10, 20, 20)
def __init__(self, parent=None): super().__init__(parent) # Is it not confusing that QStandardItemModel is in QtGui # yet other models are all in QtCore??? # who's responsible for this weird organization # All selectors will refer back to the same models # this way we only need to update one set of models and all selectors will be updated self.blockComboModel: QtGui.QStandardItemModel = QtGui.QStandardItemModel( ) self.handlerComboModel: QtGui.QStandardItemModel = QtGui.QStandardItemModel( ) # All output Types are already known at runtime # But availability is determined per item self.typeModel: QtCore.QStringListModel = QtCore.QStringListModel( [val.value for val in outputTypesEnum]) self.outputViewModels = {}
def __init__(self, parent, filter_widget): super().__init__(parent) self.filter_widget = filter_widget self.setFixedSize(10, 10) # Palette pal = self.palette() pal.setColor(QtGui.QPalette.Normal, QtGui.QPalette.Window, QtGui.QColor("#008800")) self.setPalette(pal) self.setAutoFillBackground(True)
def sizeHint(self, option, index): fm = option.fontMetrics if index.column() == TEU: return QtCore.QSize(fm.width("9,999,999"), fm.height()) if index.column() == DESCRIPTION: text = index.model().data(index) document = QtGui.QTextDocument() document.setDefaultFont(option.font) document.setHtml(text) return QtCore.QSize(document.idealWidth() + 5, fm.height()) return QtWidgets.QStyledItemDelegate.sizeHint(self, option, index)
def Text(self, x, y, text, font): # since GraphicsView swaps already y-coordinate, text needs to be # flipped back self.scale = (1, -1) thetext = QtGui.QStaticText(text) size = thetext.size() self.rect = QtCore.QRectF(x, y, size.width(), size.height()) self.font = font self.method = 'drawStaticText' self.args = [x, y, thetext] self.shape.addText(x, y, font, text)
def _reload_scene_view(self, scenes): self._scn_mdl.clear() for module_name, sub_scenes in scenes: qitem_script = QtGui.QStandardItem(module_name) for scene_name, scene_doc, widgets_specs in sub_scenes: scene_data = (module_name, scene_name, widgets_specs) # update cached widget specs if module and scene match if self._current_scene_data: cur_module_name, cur_scene_name, _ = self._current_scene_data if module_name == cur_module_name and scene_name == cur_scene_name: self._current_scene_data = scene_data qitem_func = QtGui.QStandardItem(scene_name) if scene_doc: qitem_func.setToolTip(scene_doc.strip()) qitem_script.appendRow(qitem_func) qitem_func.setData(scene_data) self._scn_mdl.appendRow(qitem_script) self._scn_view.expandAll()
def __init__(self, clipboard): QPushButton.__init__(self) self.clipboard = clipboard self.prefix = '<< INITIAL PREFIX >>' self.players: PlayerListItem = [] self.mode = StatsType.ZONE self.fame = 0.0 self.clicked.connect(self.copy) self.setIcon(QtGui.QIcon(assets.path('copy.png'))) self.setToolTip("Copy to clipboard")
def __init__(self): super(Node, self).__init__() self.setFlag(QtWidgets.QGraphicsPathItem.ItemIsMovable) self.setFlag(QtWidgets.QGraphicsPathItem.ItemIsSelectable) self._title_text = "Title" self._type_text = "base" self._width = 30 # The Width of the node self._height = 30 # the height of the node self._ports = [] # A list of ports self.node_color = QtGui.QColor(20, 20, 20, 200) self.title_path = QtGui.QPainterPath() # The path for the title self.type_path = QtGui.QPainterPath() # The path for the type self.misc_path = QtGui.QPainterPath() # a bunch of other stuff self.horizontal_margin = 30 # horizontal margin self.vertical_margin = 15 # vertical margin
def __init__(self, *args, **kwargs): super(Details, self).__init__(*args, **kwargs) self.setReadOnly(True) self.font = QtGui.QFontDatabase.systemFont( QtGui.QFontDatabase.FixedFont) self.font.setPointSize(12) self.setFont(self.font) self.backgroundColor = QtGui.QColor(33, 33, 33) self.textColor = QtGui.QColor(180, 180, 180) self.highlightColor = QtGui.QColor(255, 198, 109) self.keywordColor = QtGui.QColor(204, 120, 50) self.palette = QtGui.QPalette() self.palette.setColor(QtGui.QPalette.Base, self.backgroundColor) self.palette.setColor(QtGui.QPalette.Text, self.textColor) self.palette.setColor(QtGui.QPalette.BrightText, self.highlightColor) self.palette.setColor(QtGui.QPalette.Link, self.keywordColor) self.setPalette(self.palette) self.highlighter = OTIOSyntaxHighlighter(self.palette, self.document())
def draw_color_square(self, color): """ Create a color square. :param color: QColor object :return: Color square widget. """ color_square_label = QtWidgets.QLabel() color_square_pix = QtGui.QPixmap(15, 15) color_square_pix.fill(color) color_square_label.setPixmap(color_square_pix) return color_square_label
def init_gui(self): """Separate function for GUI initialization""" block_widgets = [ PanelBlockView(conf["abbr-ua"], conf["abbr"]) for conf in block_configs ] self._init_layout(block_widgets + [""], is_vertical=False, margins=(5, 5, 5, 5), spacing=5) self._init_palette({qtg.QPalette.Window: qtg.QColor("#526760")})
def paintEvent(self, event: QPaintEvent) -> None: opt = Qtw.QStyleOption() opt.initFrom(self) painter = QtGui.QPainter(self) # painter.setBackgroundMode(Qt.TransparentMode) s = self.style() s.drawPrimitive(Qtw.QStyle.PE_Widget, opt, painter, self) self.resizePcs()
def paint(self, painter, option, widget=None): if (self.myStartItem.collidesWithItem(self.myEndItem)): return myStartItem = self.myStartItem myEndItem = self.myEndItem myColor = self.myColor myPen = self.pen() myPen.setColor(self.myColor) arrowSize = 20.0 painter.setPen(myPen) painter.setBrush(self.myColor) centerLine = QtCore.QLineF(myStartItem.pos(), myEndItem.pos()) endPolygon = myEndItem.polygon() p1 = endPolygon.at(0) + myEndItem.pos() intersectPoint = QtCore.QPointF() for i in endPolygon: p2 = i + myEndItem.pos() polyLine = QtCore.QLineF(p1, p2) intersectType, intersectPoint = polyLine.intersect(centerLine) if intersectType == QtCore.QLineF.BoundedIntersection: break p1 = p2 self.setLine(QtCore.QLineF(intersectPoint, myStartItem.pos())) line = self.line() angle = math.acos(line.dx() / line.length()) if line.dy() >= 0: angle = (math.pi * 2.0) - angle arrowP1 = line.p1() + QtCore.QPointF( math.sin(angle + math.pi / 3.0) * arrowSize, math.cos(angle + math.pi / 3) * arrowSize) arrowP2 = line.p1() + QtCore.QPointF( math.sin(angle + math.pi - math.pi / 3.0) * arrowSize, math.cos(angle + math.pi - math.pi / 3.0) * arrowSize) self.arrowHead.clear() for point in [line.p1(), arrowP1, arrowP2]: self.arrowHead.append(point) painter.drawLine(line) painter.drawPolygon(self.arrowHead) if self.isSelected(): painter.setPen(QtGui.QPen(myColor, 1, QtCore.Qt.DashLine)) myLine = QtCore.QLineF(line) myLine.translate(0, 4.0) painter.drawLine(myLine) myLine.translate(0, -8.0) painter.drawLine(myLine)
def __init__(self, itemMenu, parent=None): super(DiagramScene, self).__init__(parent) self.myItemMenu = itemMenu self.myMode = self.MoveItem self.myItemType = DiagramItem.Step self.line = None self.textItem = None self.myItemColor = QtCore.Qt.white self.myTextColor = QtCore.Qt.black self.myLineColor = QtCore.Qt.black self.myFont = QtGui.QFont()
def __create_texture(self, image): texture = QtOpenGL.QOpenGLTexture(QtOpenGL.QOpenGLTexture.Target2D) texture.setMinMagFilters(QtOpenGL.QOpenGLTexture.Filter.Nearest, QtOpenGL.QOpenGLTexture.Filter.Linear) texture.setBorderColor(0, 0, 0, 1) texture.setWrapMode(QtOpenGL.QOpenGLTexture.ClampToBorder) texture.setAutoMipMapGenerationEnabled(False) texture.DontGenerateMipMaps = True texture.setData( QtGui.QImage(image, image.shape[1], image.shape[0], QtGui.QImage.Format_RGBA8888).mirrored()) return texture
def __init__(self, name, value): super().__init__(name) self._color_btn = QtWidgets.QPushButton() color = QtGui.QColor() color.setRgbF(*value) color_name = color.name() self._color_btn.setStyleSheet("background-color: %s;" % color_name) self._label = QtWidgets.QLabel(self.get_label_text(color_name)) self._color_btn.pressed.connect(self._pick_color) self._qcolor = color self.layout.addWidget(self._label) self.layout.addWidget(self._color_btn)
def draw_connectivity(self, vertices, deleted_nodes): self.connections = list() # instantiate a graphics item marker = gic.GraphicsCollection() # set its properties marker.pen.setColor(QtGui.QColor(60, 60, 255, 255)) marker.brush.setColor(QtGui.QColor(255, 50, 50, 230)) marker.pen.setWidthF(1.6) # no pen thickness change when zoomed marker.pen.setCosmetic(True) for node in deleted_nodes: marker.Circle(vertices[node][0], vertices[node][1], 0.003) marker_item = GraphicsItem.GraphicsItem(marker) self.connections.append(marker_item) # add to the scene self.connections = self.mainwindow.scene. \ createItemGroup(self.connections)
def _add_medias(self, *paths): for path in paths[::-1]: try: media = Media(path) except Exception: print(f"Unable to add media {path}") else: self._config.set_medias_last_dir(op.dirname(path)) item = QtGui.QStandardItem(path) item.setData(media) self._model.insertRow(0, item) self._update_cfg()