Can't paint over QVideoWidget in Qt6
-
It used to work in Qt5 with QCameraViewfinder but I can't make it work in Qt6. Here is an example:
#include <QApplication> #include <QCamera> #include <QMediaDevices> #include <QMediaCaptureSession> #include <QVideoWidget> #include <QPainter> class myVideoWidget : public QVideoWidget { public: explicit myVideoWidget(QWidget* parent = nullptr) : QVideoWidget(parent) { } protected: void paintEvent(QPaintEvent* event) override { QVideoWidget::paintEvent(event); QPainter painter(this); QPen pen; pen.setWidth(20); pen.setColor(Qt::black); painter.setPen(pen); painter.drawRect(10, 10, 500, 500); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); myVideoWidget videoWidget; videoWidget.resize(640, 480); videoWidget.show(); QCamera camera(QMediaDevices::defaultVideoInput()); camera.start(); QMediaCaptureSession mediaCaptureSession; mediaCaptureSession.setCamera(&camera); mediaCaptureSession.setVideoOutput(&videoWidget); return a.exec(); } -
Hi and welcome to devnet,
The architecture of the multimedia module has greatly changed for Qt 6.
Taking a quick look at the QVideoWidget implementation, the RHI backend is used by default which means that OpenGL will be used for rendering unless it cannot initialize any of the accelerated backends.
AFAIR, you have to implement your own QVideoSink to modify the frame.
-
Hi and welcome to devnet,
The architecture of the multimedia module has greatly changed for Qt 6.
Taking a quick look at the QVideoWidget implementation, the RHI backend is used by default which means that OpenGL will be used for rendering unless it cannot initialize any of the accelerated backends.
AFAIR, you have to implement your own QVideoSink to modify the frame.