Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. semi Transparent qlabel background
Forum Updated to NodeBB v4.3 + New Features

semi Transparent qlabel background

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 9.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • QT-static-prgmQ Offline
    QT-static-prgmQ Offline
    QT-static-prgm
    wrote on last edited by
    #1

    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.

    J.HilkJ 1 Reply Last reply
    0
    • QT-static-prgmQ QT-static-prgm

      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.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @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.
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • QT-static-prgmQ Offline
        QT-static-prgmQ Offline
        QT-static-prgm
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          alt text

          1 Reply Last reply
          0
          • QT-static-prgmQ Offline
            QT-static-prgmQ Offline
            QT-static-prgm
            wrote on last edited by
            #5

            @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

            mrjjM 1 Reply Last reply
            0
            • QT-static-prgmQ QT-static-prgm

              @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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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();
              }
              
              
              1 Reply Last reply
              4

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved