Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't paint over QVideoWidget in Qt6
Qt 6.12 LTS is out! See what's new in the release blog

Can't paint over QVideoWidget in Qt6

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 800 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MartCh
    wrote on last edited by
    #1

    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();
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      1
      • SGaistS SGaist

        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.

        M Offline
        M Offline
        MartCh
        wrote on last edited by
        #3

        @SGaist Ok thanks! I will try to do that but I am really not an expert :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved