Exemplo n.º 1
0
    def paintEvent(self, event):
        super(PixmapWidget, self).paintEvent(event)
        if not self.pixmap or self.pixmap.isNull():
            return
        p = QPainter(self)

        source = QRect(0, 0, self.pixmap.width(), self.pixmap.height())

        sw = float(source.width())
        sh = float(source.height())
        tw = float(self.width())+1
        th = float(self.height())+1
        tx = 0
        ty = 0
        if sw/tw > sh/th:
            ntw = tw
            nth = sh/sw*tw
            ty = (th-nth)/2
        else:
            nth = th
            ntw = sw/sh*th
            tx = (tw-ntw)/2

        target = QRect(tx, ty, ntw, nth)

        p.setBrush(self.bgBrush)
        p.setPen(self.bgPen)
        p.drawRect(self.rect())

        p.drawPixmap(target, self.pixmap, source)
Exemplo n.º 2
0
 def lineComponent(self):
     linePainter = QPainter(self)
     linePainter.setRenderHint(QPainter.Antialiasing)
     penLine = QPen()
     penLine.setStyle(self.rpb_lineStyle)
     penLine.setWidth(self.lineWidth)
     penLine.setBrush(
         QColor(self.lineColor[0], self.lineColor[1], self.lineColor[2]))
     penLine.setCapStyle(self.rpb_lineCap)
     penLine.setJoinStyle(Qt.RoundJoin)
     linePainter.setPen(penLine)
     linePainter.drawArc(self.positionX + self.posFactor,
                         self.positionY + self.posFactor,
                         self.rpb_Size - self.sizeFactor,
                         self.rpb_Size - self.sizeFactor,
                         self.startPosition, self.rpb_value)
     linePainter.end()
Exemplo n.º 3
0
    def paintEvent(self, event):
        super(QtBubbleLabel, self).paintEvent(event)
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)  # 抗锯齿

        rectPath = QPainterPath()  # 圆角矩形

        height = self.height() - 8  # 往上偏移8
        rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5)
        x = self.width() / 5 * 4
        # 边框画笔
        painter.setPen(
            QPen(self.BorderColor, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        # 背景画刷
        painter.setBrush(self.BackgroundColor)
        # 绘制形状
        painter.drawPath(rectPath)
Exemplo n.º 4
0
    def notifyImage(self, x: int, y: int, qimage: QImage, width: int,
                    height: int):
        """
        Draw an image on the buffer.
        :param x: x position of the new image
        :param y: y position of the new image
        :param qimage: new QImage
        :param width: width of the new image
        :param height: height of the new image
        """

        #fill buffer image
        qp = QPainter(self._buffer)
        qp.drawImage(x, y, qimage, 0, 0, width, height)

        #force update
        self.update()
Exemplo n.º 5
0
def paint_with_opacity(pixmap: QPixmap, opacity: float):
    transparent_image = QImage(QSize(36, 36),
                               QImage.Format_ARGB32_Premultiplied)
    transparent_image.fill(Qt.transparent)
    painter = QPainter(transparent_image)
    painter.setOpacity(opacity)
    painter.drawPixmap(18 - pixmap.width() / 2, 18 - pixmap.height() / 2,
                       pixmap)
    painter.end()
    return QPixmap.fromImage(transparent_image)
Exemplo n.º 6
0
    def paintEvent(self, event):
        painter = QPainter(self)
        self.snake.paint(painter)
        self.network_painter.paint(painter)
        painter.setPen(QPen())
        painter.drawText(170, 20, 'state: {}'.format(self.snakegenetic.state))
        painter.drawText(170, 40,
                         'generation: {}'.format(self.snakegenetic.generation))

        self.linechart.paint(painter)
Exemplo n.º 7
0
    def drawForeground(self, painter: QtGui.QPainter, rect: QtCore.QRectF):
        """Draw the foreground pixmap, updates if None."""
        if self.foreground_pixmap is None:
            self.updateForeground(rect)

        painter.save()
        painter.resetTransform()
        # Draw the actual overlay
        painter.drawPixmap(0, 0, self.foreground_pixmap)
        painter.restore()
Exemplo n.º 8
0
    def paintEvent(self, event):
        mapP = QPainter()
        mapP.begin(self)
        mapP.drawImage(self.centralGP.x(),self.centralGP.y(),self.mapPx)
        mapP.end()

        self.drawRobot(self.robotM,'blue')
        self.drawRobot(self.robotG,'purple')
        self.drawElts(self.staticElts,'black','pink')
        self.drawElts([self.robotM_traget,self.robotG_traget],'red','white')
Exemplo n.º 9
0
 def paintEvent(self,event):
     super(QPushColorButton, self).paintEvent(event)
     size = 13
     height = (self.height() - size)/2
     width = (self.width() - size)/2
     qp = QPainter(self)
     # qp.begin(self)
     qp.setPen(Qt.NoPen)
     qp.setBrush(self.currentColor)
     qp.drawRect(width, height, size, size)
Exemplo n.º 10
0
 def draw_cube(self, qp: QPainter):
     x, y = self.__cur_position
     qp.drawLine(x - self._center_shift, y - self._center_shift,
                 x + self._center_shift, y - self._center_shift)
     qp.drawLine(x + self._center_shift, y - self._center_shift,
                 x + self._center_shift, y + self._center_shift)
     qp.drawLine(x + self._center_shift, y + self._center_shift,
                 x - self._center_shift, y + self._center_shift)
     qp.drawLine(x - self._center_shift, y + self._center_shift,
                 x - self._center_shift, y - self._center_shift)
Exemplo n.º 11
0
 def paintEvent(self, event):
     pixmap = self.pixmap
     painter = QPainter(self)
     if self.isChecked(
     ):  # Todo only if rotate button is clicked rotate. we have to fix this -> src.main.PdfConverter.rotate_button(self).isClicked()
         painter.translate(self.width(), 0)
         self.rotate += 90
         self.rotate %= 360
         painter.rotate(90)
     painter.drawPixmap(event.rect(), pixmap)
Exemplo n.º 12
0
    def paintEvent(self, event):
        """
        Redraw application.
        """
        super(TileEd, self).paintEvent(event)

        painter = QPainter(self)

        painter.setPen(QColor(127, 127, 127))

        # Only update the region that need updating
        x1 = int(event.rect().x() // self.scale // self.tile_size[0]) - 1
        y1 = int(event.rect().y() // self.scale // self.tile_size[1]) - 1
        x2 = int(
            event.rect().width() // self.scale // self.tile_size[0]) + x1 + 3
        y2 = int(
            event.rect().height() // self.scale // self.tile_size[1]) + y1 + 3

        if x1 < 0:
            x1 = 0
        if y1 < 0:
            y1 = 0
        if x2 > self.size[0]:
            x2 = self.size[0]
        if y2 > self.size[1]:
            y2 = self.size[1]

        for y in range(y1, y2):
            for x in range(x1, x2):
                tile = self.get_tile(x, y)
                posx, posy = self.get_tile_map_coords(tile)
                painter.drawPixmap(x * self.tile_size[0] * self.scale,
                                   y * self.tile_size[1] * self.scale,
                                   self.tile_size[0] * self.scale,
                                   self.tile_size[1] * self.scale, self.pixmap,
                                   posx, posy, self.tile_size[0],
                                   self.tile_size[1])

                if self.show_grid:
                    painter.drawRect(x * self.tile_size[0] * self.scale,
                                     y * self.tile_size[1] * self.scale,
                                     self.tile_size[0] * self.scale,
                                     self.tile_size[1] * self.scale)

        painter.end()
Exemplo n.º 13
0
 def mousePressEvent(self, event):
     if not self._photo.pixmap().isNull():
         if event.button() == QtCore.Qt.LeftButton:
             self.save_state()
             self.start = True
             self.painter = QPainter(self.seg_image)
             if self.erase:
                 self.painter.setCompositionMode(
                     QPainter.CompositionMode_Clear)
             self.painter.setPen(self.segmenter_pen)
             self.paint_point(event.pos())
         elif event.button() == QtCore.Qt.RightButton:
             if not self._photo.pixmap().isNull():
                 self.setDragMode(QGraphicsView.ScrollHandDrag)
                 self.scroll_origin = self.mapToScene(event.pos())
             # if self._photo.isUnderMouse():
             #     self.photoClicked.emit(self.mapToScene(event.pos()).toPoint())
     super(ImageSegmenterView, self).mousePressEvent(event)
    def drawBorder(self, painter: QPainter) -> None:
        if self.__borderWidth <= 0: return

        painter.save()

        pen: QPen = QPen()
        pen.setWidth(self.__borderWidth)
        pen.setColor(self.__tempColor)

        painter.setPen(pen)
        painter.setBrush(Qt.NoBrush)
        rect: QRect = QRect(self.__borderWidth // 2,
                            self.__borderWidth // 2,
                            self.width() - self.__borderWidth,
                            self.height() - self.__borderWidth)
        painter.drawRoundedRect(rect, self.__borderRadius, self.__borderRadius)

        painter.restore()
    def paintEvent(self, event: QPaintEvent) -> None:
        # 绘制准备工作,启用反锯齿
        painter: QPainter = QPainter(self)
        painter.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing)

        # 绘制边框
        self.drawBorder(painter)
        # 绘制标题
        self.drawTitle(painter)
Exemplo n.º 16
0
    def paintEvent(self, event):
        super().paintEvent(event)
        if self._camera is not None:
            painter = QPainter(self)
            _, frame = self._camera.read()

            # Convert BGR to RGB.
            frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)

            # Scale the frame to match widget's width.
            new_width = self.width() // 4 * 4
            self.frame = imutils.resize(frame, width=new_width)

            # Paint the frame.
            (h, w) = self.frame.shape[:2]
            self.q_image = QImage(self.frame, w, h, QImage.Format_RGB888)
            q_pixmap = QPixmap.fromImage(self.q_image)
            painter.drawPixmap(0, 0, q_pixmap)
    def __init__(self):
        super(Plotting, self).__init__()
        self.s = 60  # size
        self.hs = self.s / 2
        self.pixmap = QPixmap(self.s, self.s)
        self.plot_range = 3.0
        # self.plot(plot_sin)

        self.tick_timer = QTimer()
        self.tick_timer.setInterval(50)
        self.tick_timer.timeout.connect(self.tick)
        self.tick_timer.start()
        self.counter = 0.1

        self.painter = QPainter(self.pixmap)

        self.painter.fillRect(QRect(0, 0, self.s, self.s), QColor())
        self.painter.translate(self.hs, self.hs)
Exemplo n.º 18
0
 def paint(
     self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex
 ):
     model = index.model()
     value = model.data(index, Qt.DisplayRole)
     if index not in self._dict_frames or isinstance(value, Group):
         frame = self.get_frame(value)
         self._dict_frames[index] = frame
     else:
         frame = self._dict_frames[index]
     frame.setFixedSize(option.rect.size())
     ratio = self.parent().devicePixelRatioF()
     pixmap = QPixmap(frame.size() * ratio)
     pixmap.setDevicePixelRatio(ratio)
     frame.render(pixmap, QPoint(), QRegion())
     painter.drawPixmap(option.rect, pixmap)
     if index in self.parent().selectedIndexes():
         fill_selection(option, painter)
    def paintEvent(self, event: QPaintEvent) -> None:
        # 绘制准备工作,启用反锯齿
        painter: QPainter = QPainter(self)
        painter.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing)

        # 绘制背景
        self.drawBg(painter)
        # 绘制文字
        self.drawText(painter)
Exemplo n.º 20
0
    def paintEvent(self, event):
        p = QPainter(self)
        # 선 모두 그리기
        for _ in self.map_mem['L'].keys():
            self.draw_line(p, self.map_mem['L'][_])
        for _ in self.map_mem['R'].keys():
            self.draw_box(p, self.map_mem['R'][_])

        self.update()
Exemplo n.º 21
0
    def drawValue(self, painter: QPainter) -> None:
        if not self.__showValue: return

        radius: int = 100
        painter.save()
        painter.setPen(self.__textColor)

        font: QFont = QFont()
        font.setPixelSize(radius - 50 if self.__showPointer else radius - 15)
        font.setBold(True)
        painter.setFont(font)

        textRect: QRectF = QRectF(-radius, -radius, radius * 2, radius * 2)
        value = round(self.__value, self.__precision)
        strValue: str = str(
            int(value)) if self.__precision is 0 else str(value)
        painter.drawText(textRect, Qt.AlignCenter, strValue)
        painter.restore()
    def drawValue(self, painter: QPainter) -> None:
        painter.save()
        painter.setPen(Qt.NoPen)

        # 定义了画刷则取画刷,可以形成渐变效果
        painter.setBrush(
            QBrush(self.__valueColor if self.__valueBrush ==
                   Qt.NoBrush else self.__valueBrush))

        # 计算当前值对应的百分比
        step: float = self.__value / (self.__maxValue - self.__minValue)
        progress: int = int((self.width() - self.__padding * 2) * step)

        rect: QRect = QRect(self.__padding, (self.height() // 3) * 2, progress,
                            int(self.height() / 3))
        painter.drawRoundedRect(rect, self.__radius, self.__radius)

        painter.restore()
    def paintEvent(self, event: QPaintEvent) -> None:
        # 绘制准备工作,启用反锯齿,平移坐标轴中心,等比例缩放
        painter: QPainter = QPainter(self)
        painter.setRenderHints(QPainter.Antialiasing
                               | QPainter.TextAntialiasing)

        self.drawBg(painter)  # 绘制背景
        self.drawTip(painter)  # 绘制上部分提示信息
        self.drawValue(painter)  # 绘制进度
Exemplo n.º 24
0
 def export(self, filename):
     self.printer = QPrinter()
     self.printer.setOutputFormat(QPrinter.PdfFormat)
     self.printer.setOutputFileName(filename)
     self.printer.setPageMargins(QMarginsF(0, 0, 0, 0))
     self.printer.setResolution(96)
     self.printer.setFullPage(True)
     pages = self.document['pages']
     if pages:
         page = pages[0]
         self.printer.setPageSizeMM(QSizeF(page.width / mm, page.height / mm))
     self.painter = QPainter()
     self.painter.begin(self.printer)
     self._isFirstPage = True
     for page in pages:
         self.exportPage(page)
         self._isFirstPage = False
     self.painter.end()
Exemplo n.º 25
0
    def get_whole_scene_img(self):
        self.hide_proxies()
        img = QImage(self.sceneRect().width() / self.total_scale_div,
                     self.sceneRect().height() / self.total_scale_div,
                     QImage.Format_RGB32)
        img.fill(Qt.transparent)

        painter = QPainter(img)
        painter.setRenderHint(QPainter.Antialiasing)
        rect = QRectF()
        rect.setLeft(-self.viewport().pos().x())
        rect.setTop(-self.viewport().pos().y())
        rect.setWidth(img.rect().width())
        rect.setHeight(img.rect().height())
        # rect is right... but it only renders from the viewport's point down-and rightwards, not from topleft (0,0) ...
        self.render(painter, rect, rect.toRect())
        self.show_proxies()
        return img
Exemplo n.º 26
0
    def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignment,\
                       xOffset, yOffset, textColor, visColor):
        if backgroundFile == '':
            im = Image.new("RGB", (1280, 720), "black")
        else:
            im = Image.open(backgroundFile)

        if self._image == None or not self.lastBackgroundImage == backgroundFile:
            self.lastBackgroundImage = backgroundFile

            # resize if necessary
            if not im.size == (1280, 720):
                im = im.resize((1280, 720), Image.ANTIALIAS)

            self._image = ImageQt(im)

        self._image1 = QtGui.QImage(self._image)
        painter = QPainter(self._image1)
        font = titleFont
        font.setPixelSize(fontSize)
        painter.setFont(font)
        painter.setPen(QColor(*textColor))

        yPosition = yOffset

        fm = QtGui.QFontMetrics(font)
        if alignment == 0:  #Left
            xPosition = xOffset
        if alignment == 1:  #Middle
            xPosition = xOffset - fm.width(titleText) / 2
        if alignment == 2:  #Right
            xPosition = xOffset - fm.width(titleText)
        painter.drawText(xPosition, yPosition, titleText)
        painter.end()

        buffer = QtCore.QBuffer()
        buffer.open(QtCore.QIODevice.ReadWrite)
        self._image1.save(buffer, "PNG")

        strio = io.BytesIO()
        strio.write(buffer.data())
        buffer.close()
        strio.seek(0)
        return Image.open(strio)
Exemplo n.º 27
0
    def paintEvent(self, event: QPaintEvent):
        super().paintEvent(event)

        painter = QPainter(self)
        painter.setPen(Qt.NoPen)
        painter.setBrush(self.color)
        painter.drawRect(
            0, 0,
            round((self._value - self._min_value) /
                  (self._max_value - self._min_value) * self.width()),
            self.height())
Exemplo n.º 28
0
    def paintEvent(self, event:QPaintEvent):
        """
        draws background
        :param event:
        :return: None
        """
        custom_painter = QPainter(self)
        custom_painter.fillRect(self.rect(), self.back_color)

        custom_painter.setPen(self.border_color)
        custom_painter.drawRect(0,0, self.rect().width()-1, self.rect().height()-1)
Exemplo n.º 29
0
    def __init__(self, parent, fn, *args):
        super(LoadingBar, self).__init__(parent)

        self.fn = fn
        self.args = args
        self.worker = Worker(fn, *args)
        self.worker.signals.result.connect(
            main_window.MainWindow.get_instance().calc_done)

        main_window.MainWindow.get_instance().threadpool.start(self.worker)

        # overlay
        # make the window frameless
        self.loading_icon = QSvgRenderer('resources/images/loading_icon.svg')
        self.qp = QPainter()

        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

        self.fillColor = QColor(30, 30, 30, 120)
        self.penColor = QColor("#333333")

        self.close_btn = QPushButton(self)
        self.close_btn.setText("Abbrechen")

        font = QFont()
        font.setPixelSize(18)
        font.setBold(True)
        self.close_btn.setFont(font)
        self.close_btn.setStyleSheet("QPushButton {"
                                     "background-color: #EAEAEA;"
                                     "border: None;"
                                     "padding-top: 12px;"
                                     "padding-bottom: 12px;"
                                     "padding-left: 20px;"
                                     "padding-right: 20px;"
                                     "}"
                                     "QPushButton:hover {"
                                     "background-color: #DFDFDF;"
                                     "}")
        #self.close_btn.setFixedSize(30, 30)
        self.close_btn.clicked.connect(self._onclose)

        self.signals = LoadingBarSignals()
Exemplo n.º 30
0
    def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem,
              widget: QWidget) -> None:
        """
		Paint the graphics of the action wrapper including action name, number, and ports.

		:param painter: This draws the widget.
		:type painter: QPainter
		:param option: Option for the style of graphic.
		:type option: QStyleOptionGraphicsItem
		:param widget: Index for the painted graphic.
		:type widget: QWidget
		:return: None
		:rtype: NoneType
		"""

        pen = QPen()
        pen.setColor(self.lineColor)
        pen.setWidth(MoveButton.PEN_WIDTH)
        painter.setPen(pen)
        painter.setBrush(self.bgColor)

        x = -MoveButton.WIDTH / 2
        y = -MoveButton.HEIGHT / 2

        painter.drawRect(x, y, MoveButton.WIDTH, MoveButton.HEIGHT)

        # calculate arrow points as if it were facing down, then flip if necessary.
        vertexX = 0
        vertexY = MoveButton.HEIGHT / 4
        leftX = -MoveButton.WIDTH / 4
        leftY = -MoveButton.HEIGHT / 4
        rightX = MoveButton.WIDTH / 4
        rightY = -MoveButton.HEIGHT / 4

        if self.direction == MoveButton.Direction.Up:
            vertexX *= -1
            vertexY *= -1
            leftX *= -1
            leftY *= -1
            rightX *= -1
            rightY *= -1

        painter.drawLine(vertexX, vertexY, rightX, rightY)
        painter.drawLine(vertexX, vertexY, leftX, leftY)
Exemplo n.º 31
0
    def _draw_objects(self, painter: QPainter, level: Level):
        for level_object in level.get_all_objects():
            level_object.render()
            level_object.draw(painter, self.block_length, self.transparency)

            if level_object.selected:
                painter.save()

                painter.setPen(QPen(QColor(0x00, 0x00, 0x00, 0x80), width=1))
                painter.drawRect(level_object.get_rect(self.block_length))

                painter.restore()
Exemplo n.º 32
0
 def _drawTiles(self, source):
     x = self.padding
     y = self.padding
     sx = 0
     sy = 0
     doReorder = self.forcePot & self.reorder
     painter = QPainter(self._target)
     for j in range(self._rows):
         for i in range(self._cols):
             painter.drawPixmap(x, y, source, sx, sy, self.tileWidth, self.tileHeight)
             x += self._gridWidth
             if doReorder and x >= self._targetWidth - self._gridWidth:
                 x = self.padding
                 y += self._gridHeight
             sx += self.tileWidth
         if not doReorder:
             x = self.padding
             y += self._gridHeight
         sx = 0
         sy += self.tileHeight
Exemplo n.º 33
0
 def createDropTextPixmap(self):
     pixmap = QPixmap(481, 300)
     pixmap.fill(QColor("#333333"))
     painter = QPainter(pixmap)
     font = QFont("Arial")
     font.setPixelSize(28)
     font.setBold(True)
     fm = QFontMetrics(font)
     painter.setFont(font)
     painter.setPen(QPen(QColor("#888888"), 1))
     text = "Drop the tileset image here"
     x = (pixmap.width()-fm.width(text))/2
     y = (pixmap.height()+fm.height())/2
     painter.drawText(x, y, text)
     del painter
     return pixmap
Exemplo n.º 34
0
 def paint(self, painter: QPainter, styleOption: QStyleOptionGraphicsItem, widget: QWidget=None):
     pen = QPen()
     pen.setWidthF(0.05)
     pen.setColor(Qt.darkGray)
     painter.setPen(pen)
     brush = QBrush()
     brush.setColor(self.color)
     brush.setStyle(Qt.SolidPattern)
     painter.setBrush(brush)
     topLeft = QPointF(0, 0)
     bottomRight = QPointF(1, 1)
     rectangle = QRectF(topLeft, bottomRight)
     rectangle.translate(-0.5, -0.5)
     painter.drawRect(rectangle)
Exemplo n.º 35
0
    def testFromData(self):
        picture = QPicture()
        painter = QPainter()
        painter.begin(picture)
        painter.drawEllipse(10, 20, 80, 70)
        painter.end()

        data = picture.data()
        picture2 = QPicture()
        picture2.setData(data)

        self.assertEqual(picture2.data(), picture.data())

        w = MyWidget()
        w._picture = picture2
        w._app = self.app

        QTimer.singleShot(300, w.show)
        self.app.exec_()
Exemplo n.º 36
0
    def paintEvent(self, event):
        rect = QRect(10, 20, 80, 60)

        path = QPainterPath()
        path.moveTo(20, 80)
        path.lineTo(20, 30)
        path.cubicTo(80, 0, 50, 50, 80, 80)

        startAngle = 30 * 16
        arcLength = 120 * 16

        painter = QPainter(self)
        painter.setPen(self.pen)
        painter.setBrush(self.brush)
        if self.antialiased:
            painter.setRenderHint(QPainter.Antialiasing)

        for x in range(0, self.width(), 100):
            for y in range(0, self.height(), 100):
                painter.save()
                painter.translate(x, y)
                if self.transformed:
                    painter.translate(50, 50)
                    painter.rotate(60.0)
                    painter.scale(0.6, 0.9)
                    painter.translate(-50, -50)

                if self.shape == RenderArea.Line:
                    painter.drawLine(rect.bottomLeft(), rect.topRight())
                elif self.shape == RenderArea.Points:
                    painter.drawPoints(RenderArea.points)
                elif self.shape == RenderArea.Polyline:
                    painter.drawPolyline(RenderArea.points)
                elif self.shape == RenderArea.Polygon:
                    painter.drawPolygon(RenderArea.points)
                elif self.shape == RenderArea.Rect:
                    painter.drawRect(rect)
                elif self.shape == RenderArea.RoundedRect:
                    painter.drawRoundedRect(rect, 25, 25, Qt.RelativeSize)
                elif self.shape == RenderArea.Ellipse:
                    painter.drawEllipse(rect)
                elif self.shape == RenderArea.Arc:
                    painter.drawArc(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Chord:
                    painter.drawChord(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Pie:
                    painter.drawPie(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Path:
                    painter.drawPath(path)
                elif self.shape == RenderArea.Text:
                    painter.drawText(rect, Qt.AlignCenter,
                                     "PySide 2\nQt %s" % qVersion())
                elif self.shape == RenderArea.Pixmap:
                    painter.drawPixmap(10, 10, self.pixmap)

                painter.restore()

        painter.setPen(self.palette().dark().color())
        painter.setBrush(Qt.NoBrush)
        painter.drawRect(QRect(0, 0, self.width() - 1, self.height() - 1))
Exemplo n.º 37
0
 def paintEvent(self, e):
     p = QPainter(self)
     self._info = p.fontInfo()
     self._app.quit()
Exemplo n.º 38
0
    def paintEvent(self, paintEvent: QPaintEvent):
        pen = QPen()
        pen.setJoinStyle(Qt.RoundJoin)
        pen.setCapStyle(Qt.RoundCap)
        painter = QPainter(self)
        painter.translate(self.paintOffset)
        painter.setBackgroundMode(Qt.TransparentMode)
        painter.setRenderHint(QPainter.Antialiasing)

        if self.nodes is not None:
            painted = set()

            def paintNode(node):
                nonlocal painter, painted
                if node in painted:
                    return
                painted.add(node)
                for link in node.links:
                    if link not in painted:
                        painter.drawLine(node.point, link.point)
                        paintNode(link)

            color = self.palette().color(QPalette.Dark)
            pen.setColor(color)
            pen.setWidth(0.50 * self.paintStep)
            painter.setPen(pen)
            for node in self.nodes.values():
                if paintEvent.region().contains(node.point):
                    paintNode(node)

        if self.startNode is not None:
            color = self.palette().color(QPalette.Dark)
            pen.setColor(color)
            pen.setWidth(0.75 * self.paintStep)
            painter.setPen(pen)
            if paintEvent.region().contains(self.startNode.point):
                painter.drawPoint(self.startNode.point)

        if self.finishNode is not None and paintEvent.region().contains(self.finishNode.point):
            color = self.palette().color(QPalette.Dark).darker(120)
            pen.setColor(color)
            pen.setWidth(0.75 * self.paintStep)
            painter.setPen(pen)
            painter.drawPoint(self.finishNode.point)

        if self.player is not None:
            color = self.palette().color(QPalette.Highlight)
            color.setAlpha(196)
            pen.setColor(color)
            pen.setWidth(0.90 * self.paintStep)
            painter.setPen(pen)
            painter.drawPoint(self.player)

        del painter, pen
Exemplo n.º 39
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.fillRect(self.rect(), Qt.black)

        if self.pixmap.isNull():
            painter.setPen(Qt.white)
            painter.drawText(self.rect(), Qt.AlignCenter,
                    "Rendering initial image, please wait...")
            return

        if self.curScale == self.pixmapScale:
            painter.drawPixmap(self.pixmapOffset, self.pixmap)
        else:
            scaleFactor = self.pixmapScale / self.curScale
            newWidth = int(self.pixmap.width() * scaleFactor)
            newHeight = int(self.pixmap.height() * scaleFactor)
            newX = self.pixmapOffset.x() + (self.pixmap.width() - newWidth) / 2
            newY = self.pixmapOffset.y() + (self.pixmap.height() - newHeight) / 2

            painter.save()
            painter.translate(newX, newY)
            painter.scale(scaleFactor, scaleFactor)
            exposed, _ = painter.matrix().inverted()
            exposed = exposed.mapRect(self.rect()).adjusted(-1, -1, 1, 1)
            painter.drawPixmap(exposed, self.pixmap, exposed)
            painter.restore()

        text = "Use mouse wheel or the '+' and '-' keys to zoom. Press and " \
                "hold left mouse button to scroll."
        metrics = painter.fontMetrics()
        textWidth = metrics.width(text)

        painter.setPen(Qt.NoPen)
        painter.setBrush(QColor(0, 0, 0, 127))
        painter.drawRect((self.width() - textWidth) / 2 - 5, 0, textWidth + 10,
                metrics.lineSpacing() + 5)
        painter.setPen(Qt.white)
        painter.drawText((self.width() - textWidth) / 2,
                metrics.leading() + metrics.ascent(), text)
Exemplo n.º 40
0
    def paintEvent(self, event):
        contents_y = self.edit.verticalScrollBar().value()
        page_bottom = contents_y + self.edit.viewport().height()
        font_metrics = self.fontMetrics()
        current_block = self.edit.document().findBlock(self.edit.textCursor().position())
        painter = QPainter(self)
        line_count = 0
        block = self.edit.document().begin()
        while block.isValid():
            line_count += 1
            position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()
            if position.y() > page_bottom:
                break
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)
                self.current = line_count
            painter.drawText(self.width() - font_metrics.width(str(line_count)) - 10,
                             round(position.y()) - contents_y + font_metrics.ascent(),
                             str(line_count))
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            block = block.next()
        self.highest_line = line_count
        painter.end()

        QWidget.paintEvent(self, event)
Exemplo n.º 41
0
 def paintEvent(self, e):
     p = QPainter(self)
     p.drawPicture(0, 0, self._picture)
     self._app.quit()
Exemplo n.º 42
0
        def paintEvent(self, paintEvent: QPaintEvent):
            painter = QPainter(self)
            painter.setBackgroundMode(Qt.TransparentMode)
            painter.setRenderHint(QPainter.Antialiasing)
            brush = QBrush()
            brush.setStyle(Qt.SolidPattern)
            pen = QPen()
            pen.setJoinStyle(Qt.RoundJoin)
            pen.setCapStyle(Qt.RoundCap)

            center = QPoint(self.width() // 2, self.height() // 2)
            radius = 0.45 * min(self.width(), self.height())

            pen.setColor(self.palette().color(self.color[0]))
            brush.setColor(self.palette().color(self.color[1]))
            if self.highlight is True:
                pen.setColor(self.palette().color(QPalette.Highlight))
            pen.setWidth(round(0.15 * radius))
            painter.setBrush(brush)
            painter.setPen(pen)
            painter.drawEllipse(center, radius, radius)

            if self.checked is True:
                brush.setColor(self.palette().color(QPalette.Background))
                pen.setColor(self.palette().color(QPalette.Background))
                painter.setPen(pen)
                painter.setBrush(brush)
                painter.drawEllipse(center, 0.40 * radius, 0.40 * radius)
            del painter, brush, pen
Exemplo n.º 43
0
 def testSetBrushGradient(self):
     painter = QPainter()
     gradient = QLinearGradient(0, 0, 0, 0)
     painter.setBrush(gradient)
Exemplo n.º 44
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, self.antialiased)
        painter.translate(self.width() / 2, self.height() / 2)

        for diameter in range(0, 256, 9):
            delta = abs((self.frameNo % 128) - diameter / 2)
            alpha = 255 - (delta * delta) / 4 - diameter
            if alpha > 0:
                painter.setPen(QPen(QColor(0, diameter / 2, 127, alpha), 3))

                if self.floatBased:
                    painter.drawEllipse(QRectF(-diameter / 2.0,
                            -diameter / 2.0, diameter, diameter))
                else:
                    painter.drawEllipse(QRect(-diameter / 2,
                            -diameter / 2, diameter, diameter))
Exemplo n.º 45
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.setPen(Qt.NoPen)
     self.penFromEnum = painter.pen()
     painter.setPen(int(Qt.NoPen))
     self.penFromInteger = painter.pen()
Exemplo n.º 46
0
 def setUp(self):
     self.painter = QPainter()
     self.text = "teste!"
Exemplo n.º 47
0
class QPainterDrawText(unittest.TestCase):
    def setUp(self):
        self.painter = QPainter()
        self.text = "teste!"

    def tearDown(self):
        del self.text
        del self.painter

    def testDrawText(self):
        # bug #254
        rect = self.painter.drawText(100, 100, 100, 100, Qt.AlignCenter | Qt.TextWordWrap, self.text)
        self.assert_(isinstance(rect, QRect))

    def testDrawTextWithRect(self):
        # bug #225
        rect = QRect(100, 100, 100, 100)
        newRect = self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap, self.text)

        self.assert_(isinstance(newRect, QRect))

    def testDrawTextWithRectF(self):
        """QPainter.drawText(QRectF, ... ,QRectF*) inject code"""
        rect = QRectF(100, 52.3, 100, 100)
        newRect = self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap, self.text)

        self.assert_(isinstance(newRect, QRectF))

    def testDrawOverloads(self):
        """Calls QPainter.drawLines overloads, if something is
           wrong Exception and chaos ensues. Bug #395"""
        self.painter.drawLines([QLine(QPoint(0, 0), QPoint(1, 1))])
        self.painter.drawLines([QPoint(0, 0), QPoint(1, 1)])
        self.painter.drawLines([QPointF(0, 0), QPointF(1, 1)])
        self.painter.drawLines([QLineF(QPointF(0, 0), QPointF(1, 1))])
        self.painter.drawPoints([QPoint(0, 0), QPoint(1, 1)])
        self.painter.drawPoints([QPointF(0, 0), QPointF(1, 1)])
        self.painter.drawConvexPolygon(
            [QPointF(10.0, 80.0), QPointF(20.0, 10.0), QPointF(80.0, 30.0), QPointF(90.0, 70.0)]
        )
        self.painter.drawConvexPolygon([QPoint(10.0, 80.0), QPoint(20.0, 10.0), QPoint(80.0, 30.0), QPoint(90.0, 70.0)])
        self.painter.drawPolygon([QPointF(10.0, 80.0), QPointF(20.0, 10.0), QPointF(80.0, 30.0), QPointF(90.0, 70.0)])
        self.painter.drawPolygon([QPoint(10.0, 80.0), QPoint(20.0, 10.0), QPoint(80.0, 30.0), QPoint(90.0, 70.0)])
        self.painter.drawPolyline([QPointF(10.0, 80.0), QPointF(20.0, 10.0), QPointF(80.0, 30.0), QPointF(90.0, 70.0)])
        self.painter.drawPolyline([QPoint(10.0, 80.0), QPoint(20.0, 10.0), QPoint(80.0, 30.0), QPoint(90.0, 70.0)])