semi Transparent qlabel background



  • Hi,

    i want a semi transparent qlabel with round corners and solid text.

    #include <QtWidgets/QApplication>
    #include <qlabel.h>
    
    int main(int argc, char *argv[])
    {
    	QApplication a(argc, argv);
    	QLabel* label = new QLabel;
    
    	label->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen);
    	//label->setAttribute(Qt::WA_TranslucentBackground);
    	label->setAttribute(Qt::WA_ShowWithoutActivating);
    	label->setGeometry(320, 200, 750, 360);
    	label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
    	label->setStyleSheet("border-style:solid; background-color: rgba(255, 0, 0,255); color:rgb(0,255,0)");
    	label->setText("Hello World!");
    	label->show();
    
    	return a.exec();
    }
    
    

    label->setAttribute(Qt::WA_TranslucentBackground); makes the whole background transparent, but not semitransparent

    label->setStyleSheet("border-style:solid; background-color: rgba(255, 0, 0,10); color:rgb(0,255,0)"); changes the backgroundcolor, but under my label seams to be something solid black. So the label itself seams to be semi transparent, but what is under it?? and how do i remove it??

    label->setWindowOpacity (0); causes transparent text, too.



  • @QT-static-prgm

    Hi,

    you give your background color no transparency with a value of 255

    //change 
    label->setStyleSheet("border-style:solid; background-color: rgba(255, 0, 0,255); color:rgb(0,255,0)");
    //to
    label->setStyleSheet("border: solid 10px grey;  background-color: rgba(255, 0, 0,127); color:rgb(0,255,0)");
    
    //I added the round corners, you said you wanted, too.
    


  • Man! I'm stupid, but i'm not THAT stupid.
    Of cause i test it with different values. And as i told the transparency works, BUT(!) there is still something solid black under it


  • Qt Champions 2016

    Hi
    This is what i see on win 7 and Qt5.7, mingw compiler.

    alt text



  • @mrjj yeah that's how it looks for me, too. But it should be transparent when you change the alpha value to let's say 10. But instead it just become darker. So there needs to be something under the label. But i don't know what it is


  • Qt Champions 2016

    @QT-static-prgm
    QLabel seems to refuse by it self but inside widget, i get this
    alt text

    #include <QtWidgets/QApplication>
    #include <qlabel.h>
    
    int main(int argc, char* argv[]) {
      QApplication a(argc, argv);
      QLabel* label = new QLabel;
    
      label->setAttribute(Qt::WA_ShowWithoutActivating);
      label->setGeometry(320, 200, 750, 360);
      label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
      label->setText("Hello World!");
    
      QWidget* w = new QWidget;
      label->setParent(w);
      w->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen);
    
      label->setStyleSheet("border: solid 10px grey;  background-color: rgba(255, 0, 0,127); color:rgb(0,255,0)");
      w->setAttribute(Qt::WA_TranslucentBackground);
      w->setWindowFlags(Qt::FramelessWindowHint);
      label->show();
      w->show();
    
      return a.exec();
    }
    
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.