Layer UI Elements in Qt Designer

I have QLabel that I constantly install its pixmap (video playback). In my application, the user should be able to draw (boxes) over the video. How can I stack one of the QPaintDevice classes (QWidget, QPixmap, QImage, etc.) Directly above and with the same size as the QLabel for drawing. This element must have a transparent background, so the shapes drawn on it will be displayed above the video.

+4
source share
1 answer

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.

+4
source

Source: https://habr.com/ru/post/1391043/


All Articles