Add the widget you want to draw shapes onto as a child widget of the video label. First add a layout so that the child widget matches the size of the parent widget. The code would be something like this:
QHBoxLayout *layout = new QHBoxLayout(videoWidget); QLabel *overlayWidget = new QLabel(); overlayWidget->setAlignment(Qt::AlignCenter); overlayWidget->setText("Overlaid Text"); layout->addWidget(overlayWidget);
You should see the text overlaid on the video, and it should remain centered over the video widgets if it is changed. For your final code, you would use some kind of proprietary subclass that allows you to intercept mouse actions and draw rectangles, but this is the main idea.
source share