Search code examples
qtbackgroundtransparentlibvlcqlabel

Qt transparent label doesn't always update its background


I have 3 child widgets of the main widget which are aimed to play video files(their sizes and positions are the same, I mean they are overlaying each other and at a time one of them is shown and others are hidden)

I also have a Qlabel with a transparent background that I created as a child of main widget as well. I raised this label in order to be shown over 3 video player widgets all the time. The code part of Qlabel is below:

labelCamName = new QLabel(this);
labelCamName->resize(300,50);
labelCamName->move(110,0);

labelCamName->setStyleSheet("background-color: rgba(0,0,0,0%);color: rgba(150, 30, 30, 90%)");

labelCamName->setText("blabla");
labelCamName->raise();
labelCamName->show();

It works fine when the first video player widget that the label has been overlayed update itself(playing a video) but when it comes to change the widget playing video and show another widget to be played(not playing yet) that it shows a stationary black frame, the background of the label shows the last frame of the first video player widget. It doesn't pretend like it is a label with transparent backgroud, as shown by screenshots below:

first video Widget

second video player widget

Any suggestion why Im facing this issue and how to make the label work always transparent?

Thanks in advance. Very appreciated.


Solution

  • adding these attribute and flag to the desired Qlabel solved my problem.

    labelCamName->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    labelCamName->setAttribute(Qt::WA_TranslucentBackground);