Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Drawing overlay on QVideoWidget (5.15.2)
Forum Updated to NodeBB v4.3 + New Features

Drawing overlay on QVideoWidget (5.15.2)

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 884 Views
  • 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
    mnbv
    wrote on last edited by
    #1

    How can I draw a live animated overlay on a QVideoWidget?

    I tried subclassing it and overriding paintEvent, but it appears that paint events aren't actually used to update QVideoWidget, as the event handler is never called while the video is playing. (My intent with that was to just have a QImage with an alpha channel for the overlay, and draw it on top of the video at every paint event.)

    I also found this forum post, but, unless I'm not fully understanding the solution, the solution that the OP ultimately found there only seems appropriate for static, unchanging overlay content.

    How is the QVideoWidget rendering video (it's clearly not using standard paint events) and how can I draw overlays with dynamic content on top of it?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mnbv
      wrote on last edited by
      #2

      I figured it out; I just switched to using a QGraphicsView.

      Then, the video can be rendered to a QGraphicsVideoItem and overlay can be set by putting other graphics items (like QGraphicsPixmapItem) on top of it.

      The QGraphicsVideoItem::nativeSizeChanged signal can be used to drive any graphics item sizing logic that depends on the video size.

      E.g.

      scene_ = new QGraphicsScene(this);
      scene_->addItem(video_ = new QGraphicsVideoItem());
      scene_->addItem(overlay_ = new QGraphicsPixmapItem());
      ui_->view->setScene(scene_);
      
      connect(video_, &QGraphicsVideoItem::nativeSizeChanged, this, [this](QSizeF size) {
          video_->setSize(size);
          ui_->view->fitInView(video_, Qt::KeepAspectRatio);
      });
      

      And, when setting the overlay:

      QImage image = ...; /* some dynamically generated QImage */
      
      overlay_->setPixmap(QPixmap::fromImage(image));
      QTransform tx = QTransform::fromScale(video_->size().width() / image.width(),
                                            video_->size().height() / image.height());
      overlay_->setTransform(tx);
      

      And of course fitInView calls on the window's resize and show events as usual.

      1 Reply Last reply
      1

      • Login

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