Python PyQt5.QtGui.QPaintEvent() Examples

The following are 14 code examples for showing how to use PyQt5.QtGui.QPaintEvent(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtGui , or try the search function .

Example 1
Project: track   Author: frans-fuerst   File: mainwindow.py    License: Apache License 2.0 7 votes vote down vote up
def event(self, e):
        if not isinstance(e, (
                QtCore.QEvent,
                QtCore.QChildEvent,
                QtCore.QDynamicPropertyChangeEvent,
                QtGui.QPaintEvent,
                QtGui.QHoverEvent,
                QtGui.QMoveEvent,
                QtGui.QEnterEvent,
                QtGui.QResizeEvent,
                QtGui.QShowEvent,
                QtGui.QPlatformSurfaceEvent,
                QtGui.QWindowStateChangeEvent,
                QtGui.QKeyEvent,
                QtGui.QWheelEvent,
                QtGui.QMouseEvent,
                QtGui.QFocusEvent,
                QtGui.QHelpEvent,
                QtGui.QHideEvent,
                QtGui.QCloseEvent,
                QtGui.QInputMethodQueryEvent,
                QtGui.QContextMenuEvent,
                )):
            log().warning("unknown event: %r %r", e.type(), e)
        return super().event(e) 
Example 2
Project: interSubs   Author: oltodosel   File: interSubs.py    License: MIT License 6 votes vote down vote up
def paintEvent(self, evt: QPaintEvent):
			if not self.psuedo_line:
				self.psuedo_line = 1
				return

			x = y = 0
			y += self.fontMetrics().ascent()
			painter = QPainter(self)

			self.draw_text_n_outline(
				painter,
				x,
				y + config.outline_top_padding - config.outline_bottom_padding,
				config.outline_thickness,
				config.outline_blur,
				text = self.line
				) 
Example 3
Project: Hydra   Author: CountryTk   File: numberBar.py    License: GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, event: QPaintEvent):
        if self.isVisible():
            block: QTextBlock = self.editor.firstVisibleBlock()
            height: int = self.fontMetrics().height()
            number: int = block.blockNumber()

            painter = QPainter(self)
            painter.fillRect(event.rect(), QColor(53, 53, 53))
            # painter.drawRect(0, 0, event.rect().width() - 1, event.rect().height() - 1)
            font = painter.font()
            font.setPointSize(15)
            for blocks in self.editor.currentlyVisibleBlocks:
                bl: QTextBlock = blocks[-1]
                blockGeometry: QRectF = self.editor.blockBoundingGeometry(bl)
                offset: QPointF = self.editor.contentOffset()
                blockTop: float = float(blockGeometry.translated(offset).top() + 2)
                rect: QRect = QRect(0, blockTop, self.width(), height)
                painter.drawText(rect, Qt.AlignRight, str(bl.blockNumber() + 1))

            painter.end() 
Example 4
Project: interSubs   Author: oltodosel   File: interSubs.py    License: MIT License 5 votes vote down vote up
def paintEvent(self, evt: QPaintEvent):
			if self.highlight:
				self.highligting(config.hover_color, config.hover_underline_thickness)

	##################################################### 
Example 5
Project: nanovna-saver   Author: NanoVNA-Saver   File: Polar.py    License: GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
        qp = QtGui.QPainter(self)
        self.drawChart(qp)
        self.drawValues(qp)
        qp.end() 
Example 6
Project: nanovna-saver   Author: NanoVNA-Saver   File: Frequency.py    License: GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
        qp = QtGui.QPainter(self)
        self.drawChart(qp)
        self.drawValues(qp)
        if (len(self.data) > 0 and
                (self.data[0].freq > self.fstop or
                 self.data[len(self.data)-1].freq < self.fstart)
                and
                (len(self.reference) == 0 or
                 self.reference[0].freq > self.fstop or
                 self.reference[len(self.reference)-1].freq < self.fstart)):
            # Data outside frequency range
            qp.setBackgroundMode(QtCore.Qt.OpaqueMode)
            qp.setBackground(self.backgroundColor)
            qp.setPen(self.textColor)
            qp.drawText(self.leftMargin + self.chartWidth/2 - 70,
                        self.topMargin + self.chartHeight/2 - 20,
                        "Data outside frequency span")
        if self.draggedBox and self.draggedBoxCurrent[0] != -1:
            dashed_pen = QtGui.QPen(self.foregroundColor, 1, QtCore.Qt.DashLine)
            qp.setPen(dashed_pen)
            top_left = QtCore.QPoint(self.draggedBoxStart[0], self.draggedBoxStart[1])
            bottom_right = QtCore.QPoint(self.draggedBoxCurrent[0], self.draggedBoxCurrent[1])
            rect = QtCore.QRect(top_left, bottom_right)
            qp.drawRect(rect)
        qp.end() 
Example 7
Project: nanovna-saver   Author: NanoVNA-Saver   File: Smith.py    License: GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
        qp = QtGui.QPainter(self)
        # qp.begin(self)  # Apparently not needed?
        self.drawSmithChart(qp)
        self.drawValues(qp)
        qp.end() 
Example 8
Project: SnakeAI   Author: Chrispresso   File: snake_app.py    License: MIT License 5 votes vote down vote up
def paintEvent(self, event: QtGui.QPaintEvent) -> None:
        painter = QtGui.QPainter()
        painter.begin(self)

        self.draw_border(painter)
        self.draw_apple(painter)
        self.draw_snake(painter)
        
        painter.end() 
Example 9
Project: SnakeAI   Author: Chrispresso   File: nn_viz.py    License: MIT License 5 votes vote down vote up
def paintEvent(self, event: QtGui.QPaintEvent) -> None:
        painter = QtGui.QPainter()
        painter.begin(self)

        self.show_network(painter)
        
        painter.end() 
Example 10
Project: Hydra   Author: CountryTk   File: foldArea.py    License: GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, event: QPaintEvent):

        if self.isVisible():

            block: QTextBlock = self.editor.firstVisibleBlock()
            height: int = self.fontMetrics().height()
            number: int = block.blockNumber()

            painter = QPainter(self)
            painter.fillRect(event.rect(), QColor(53, 53, 53))
            font = painter.font()
            font.setPointSize(15)

            for blocks in self.editor.currentlyVisibleBlocks:

                bl: QTextBlock = blocks[-1]
                blockGeometry: QRectF = self.editor.blockBoundingGeometry(bl)
                offset: QPointF = self.editor.contentOffset()
                blockTop: int = int(blockGeometry.translated(offset).top() + 1)
                pattern = re.compile(
                    "\\s*(def|class|with|if|else|elif|for|while|async).*:")
                if pattern.match(bl.text()):

                    options = QStyleOptionViewItem()
                    options.rect = QRect(0, blockTop, self.width(), height)
                    options.state = (QStyle.State_Active |
                                     QStyle.State_Item |
                                     QStyle.State_Children)

                    if bl.userState() == UNFOLDED_STATE:
                        options.state |= QStyle.State_Open

                    self.style().drawPrimitive(QStyle.PE_IndicatorBranch, options,
                                               painter, self)
            painter.end() 
Example 11
Project: Hydra   Author: CountryTk   File: guideLinesPainter.py    License: GNU General Public License v3.0 5 votes vote down vote up
def drawLines(self, event: QPaintEvent):
        pass 
Example 12
Project: CvStudio   Author: haruiz   File: switch_button.py    License: MIT License 5 votes vote down vote up
def paintEvent(self, e: QtGui.QPaintEvent) -> None:
        if self.isChecked():
            self.setIcon(self._checked_icon)
        else:
            self.setIcon(self._unchecked_icon)
        super(SwitchButton, self).paintEvent(e) 
Example 13
Project: Python-CTPAPI   Author: nicai0609   File: candle_demo.py    License: MIT License 5 votes vote down vote up
def paintEvent(self, event: QtGui.QPaintEvent) -> None:
        """
        Reimplement this method of parent to update current max_ix value.
        """
        view = self._first_plot.getViewBox()
        view_range = view.viewRange()
        self._right_ix = max(0, view_range[0][1])

        super().paintEvent(event) 
Example 14
Project: vidcutter   Author: ozmartian   File: videoslider.py    License: GNU General Public License v3.0 4 votes vote down vote up
def paintEvent(self, event: QPaintEvent) -> None:
        painter = QStylePainter(self)
        opt = QStyleOptionSlider()
        self.initStyleOption(opt)
        font = painter.font()
        font.setPixelSize(11)
        painter.setFont(font)
        if self.tickPosition() != QSlider.NoTicks:
            x = 8
            for i in range(self.minimum(), self.width(), 8):
                if i % 5 == 0:
                    h, w, z = 18, 1, 13
                else:
                    h, w, z = 8, 1, 23
                tickcolor = QColor('#8F8F8F' if self.theme == 'dark' else '#444')
                pen = QPen(tickcolor)
                pen.setWidthF(w)
                painter.setPen(pen)
                if self.tickPosition() in (QSlider.TicksBothSides, QSlider.TicksAbove):
                    y = self.rect().top() + z
                    painter.drawLine(x, y, x, y + h)
                if self.tickPosition() in (QSlider.TicksBothSides, QSlider.TicksBelow):
                    y = self.rect().bottom() - z
                    painter.drawLine(x, y, x, y - h)
                    if self.parent.mediaAvailable and i % 10 == 0 and (x + 4 + 50) < self.width():
                        painter.setPen(Qt.white if self.theme == 'dark' else Qt.black)
                        timecode = QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), x - self.offset,
                                                                  self.width() - (self.offset * 2))
                        timecode = self.parent.delta2QTime(timecode).toString(self.parent.runtimeformat)
                        painter.drawText(x + 4, y + 6, timecode)
                if x + 30 > self.width():
                    break
                x += 15
        opt.subControls = QStyle.SC_SliderGroove
        painter.drawComplexControl(QStyle.CC_Slider, opt)
        if not len(self._progressbars) and (not self.parent.thumbnailsButton.isChecked() or self.thumbnailsOn):
            for rect in self._regions:
                rect.setY(int((self.height() - self._regionHeight) / 2) - 8)
                rect.setHeight(self._regionHeight)
                brushcolor = QColor(150, 190, 78, 200) if self._regions.index(rect) == self._regionSelected \
                    else QColor(237, 242, 255, 200)
                painter.setBrush(brushcolor)
                painter.setPen(QColor(50, 50, 50, 170))
                painter.drawRect(rect)
        opt.activeSubControls = opt.subControls = QStyle.SC_SliderHandle
        painter.drawComplexControl(QStyle.CC_Slider, opt)