QLabel *label = new QLabel("Hello, World!"); label->setAutoFillBackground(true); QPalette palette = label->palette(); palette.setColor(label->backgroundRole(), Qt::red); label->setPalette(palette);
QLabel *label = new QLabel("Transparent"); QPalette palette = label->palette(); palette.setBrush(QPalette::Base, Qt::transparent); label->setPalette(palette); label->setAttribute(Qt::WA_TranslucentBackground, true);This code creates a QLabel widget with the text "Transparent", sets its background color to transparent using the QWidget backgroundRole function, and makes the widget translucent by setting the WA_TranslucentBackground attribute to true. Package library: Qt