QLabel *label = new QLabel("Hello World"); label->setAutoFillBackground(true); QPalette palette; palette.setColor(QPalette::Background, Qt::green); label->setPalette(palette);
QLabel *label = new QLabel("Enter your name:"); label->setAutoFillBackground(true);In this example, we create a new QLabel widget with the text "Enter your name:". We then set the label's auto fill background to true using the setAutoFillBackground function. The label's background color will be set to the background color of its parent widget. Package library: Qt