QtGstreamer widget with widget overlay - c++

After a long search for the answer and a lot of testing I have not been able to place a QWidget (QLabel with a semitransparent image) over a QtGstreamer widget.
When I add an QLabel with an image over the QGst::Ui::VideoWidget (which displays video from RTP stream) the area covere with the label is black and does not display the video (which is playing).
I uploaded the project to GitHub https://github.com/MatijaBosnic/QtGstOverlay (updated the code. It is much simpler and easier to read now)
How can I overlay QGst::Ui::VideoWidget with another widget?

Related

How do I use paintEvent on a QVideoWidget with transparency?

I'm working on qt5 (C +).
I use QVideoWidget to play rtsp video stream. I wanted to draw any signatures with QPainter on the displayed video. However, I obscure the video while drawing. For example, as for the drawing area, I have given half of the QVideoWidget image.
example used:
Tried adding an extra QLabel on QVideoWidget:
QLabel * label = new QLabel (ui-> videoWidget);
And then draw on the "label", but also cover the QVideoWidget.
I also added:
ui-> videoWidget-> setAttribute (Qt :: WA_X11OpenGLOverlay);
But then the transparency extends all the way to the desktop of the operating system.
Try to set the transparency of the item that you want to draw and not the transparency of the QVideoWidget.

The background image is not drawn QWidget

The application has 2 windows. One thing is MainWindow, for which a png image is set as the background through QtStyleSheet. In the class itself, the attributes Qt::WA_TranslucentBackground and Qt::FramelessWindowHint. The second is QWidget, which serves to configure the application. The problem is that in Qt Creator QWidget background image displayed normally, and when you start the application, it is empty. Images used as a background are in the resource file.
(Sorry there is not enough rating to attach images)
Here is an example:
So the background looks like in Qt Creator
And so when you start the application
What could be the problem, and how to find its cause?

Set Image as Background and Text on Top of it in qlabel

I have a PNG file with 45x45 ratio
I have Qlabel with 270x30 Pixel ratio
what I want is to insert PNG file as background and Text on it dynamilaclly.
Text length may change from large to small and vise versa,
accorindly our image changes and fit the text inside the images its mean flexible image according to the text
QPixmap pixmapTarget = QPixmap(":/.png");
pixmapTarget = pixmapTarget.scaled(250, 27, Qt::IgnoreAspectRatio , Qt::SmoothTransformation);
ui->lable_1->setIcon(pixmapTarget);
but dont to insert text in the image and how to get flexible thing accoudning to the text.
A QLabel can contain either a text or an image. Not both at same time. If you want to have an image as a background to a text, you will need to either use a QTextView and setup your text and background image as rich text, overlay two QLabel instances on top of each other with the image being the bottom one, or implement your own custom QWidget. The latter can be done in a variety of ways, including subclassing QLabel to in paintEvent first render the background image (see QPainter's documentation on how to draw a QImage or better, a QPixmap) and then call the base implementation of paintEvent to render the text.

Qt - QGraphicsScene is overlapping images

So I was following this tutorial, https://deadbird.fr/?p=800, to obtain blur behind windows in qt.. Made some changes like request a capture() when a resize event is scheduled and added a timer to update every 200ms the image with QTimer so when for example a window is minimized the background image is updated. So far so good..
But then I tested the timer and I noticed this: https://www.youtube.com/watch?v=WixIShA48jg
As you can see in the sixth second of the video the QGraphicsScene is overlapping the images, even with scene->clear();
The other problem I have is the color. I changed the background color of the dialog to blue but only the borders are blue. I also tried to put the QGraphicsView in a QFrame with transparency and blue color but no luck. Why is that?
You can find the source code in the tutorial site. My changes are visible in the video. The video is also in 720p.

Interactively editing an existing rectangle on a QPixmap?

I'm trying to creat a Dicom GUI Toolkit where the user selects some dicom images and the image of first dicom image from the selected ones will be shown. Then the user clicks on the image and the image pops out with bigger image window. In this shown bigger image, the image will consist of a red colored rectangle that contains necessary regions of the Dicom image while the unnecessary region is outside the rectangle. The user should then have the option to change the rectangle by mouse.
Until now, I have been able to show the big dicom image with the rectangle in it using QLabel which is by the following code snippets.
void MainWindow::showBigImage()
{
QPixmap bigimage;
bigimage.load(imageName.c_str());
QPainter painter(&bigimage);
painter.setPen(Qt::red);
QRectF rect(xmin, ymin, xmax, ymax);
painter.drawRect(rect);
QSize bigsize = ui->bigImageLabel->size();
ui->bigImageLabel->setPixmap(bigimage.scaled(bigsize, Qt::IgnoreAspectRatio, Qt::FastTransformation));
ui->bigImageLabel->show();
}
and the big image on the app looks like the following:
Can you please suggest me how I should now make the rectangle editable by the user where the user can set the existing red rectangle as per his or her wish?
I also tried similar thing using QGraphicsView and QGraphicsScene with the following code:
void MainWindow::showBigImage()
{
QGraphicsScene* scene = new QGraphicsScene;
scene->addPixmap(bigimage);
ui->bigImageView->setScene(scene);
ui->bigImageView->show();
}
And this code gives me the following look:
As you can see, I could not fit the image to the boundaries of QGraphicsView, could you suggest me how to do it? Could you also suggest me how to add the red rectangle(that I showed in the example using QLabel) on the QGraphicsView without adding the rectangle on the QPixmap?
In order to get the red selection rectangle, Qt provides the class QRubberBand. The docs state:
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary.
By subclassing the image object and implementing the mouse handling functions, to create the rubber band on mousePressEvent, update its position on mouseMoveEvent and grab its final rect on mouseReleaseEvent, the QRubberBand will simplify the problem.
If you want the QRubberBand to show all the time, just create it when you display the enlarged image and don't hide it on releasing the mouse button.
As for displaying the image in the QGraphicsView, the code you displayed doesn't set the geometry of the QGraphicsScene and QGraphicsView, so you're seeing a border. If you don't want that, you should set them accordingly. Also note that QGraphicsView has a function fitInView, which you could use, after having retrieved an area from the QRubberBand, in order to zoom into the selected area.