Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Display and create video from QPainter/QImage

$
0
0

My objective is to create a gif or video from paintEvents and also show on QWidget (window).

I tried to paint the frame onto a QImage and then render it onto the QWidget, but I encounter some errors. Im not sure why I get such errors, the painter is only painting on the image, and from the docs it says I can render paint device after an end() (when I do put it after an end it complains for different reasons).

https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QWidget.html#PySide6.QtWidgets.PySide6.QtWidgets.QWidget.render

Before end()

QPainter::begin: A paint device can only be painted by one painter at a time.QWidget::render: Cannot render with an inactive painter

After end(), should I not be inheriting QWidget?

QWidget::repaint: Recursive repaint detectedQPainter::begin: A paint device can only be painted by one painter at a time.QPainter::fillRect: Painter not activeQPainter::scale: Painter not activeQPainter::drawPoints: Painter not activeQPainter::end: Painter not active, abortedQPainter::begin: A paint device can only be painted by one painter at a time.QWidget::render: Cannot render with an inactive painter
class PlotWidget(QWidget):    def __init__(self, parent=None):        super().__init__(parent)        self._timer = QTimer(self)        self._timer.setInterval(100)        self._timer.timeout.connect(self.frame)        self._points = QPointList()        self._qimg = QImage(WIDTH, HEIGHT, QImage.Format_RGB32)    # I simplified the frame def    def frame(self):        self._points.clear()        self._points.append(QPoint(0,0))        self.update()    def paintEvent(self, event):        with QPainter(self._qimg) as painter:            rect = QRect(QPoint(0, 0), self.size())            painter.fillRect(rect, Qt.white)            painter.drawPoints(self._points)            self.render(self._qimg)        self._qimg.save('test.png', 'PNG') # Id like to later make it into a video. Preferably hold img in memory and append frame to video.

Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>