Qt QLabel set the background color

Two set the background color recorded below:

1, using the palette QPalette

1 QPalette label_palette;
2 label_palette.setColor(QPalette::Background, QColor(0, 0, 0));
3 ui->label->setAutoFillBackground(true);
4 ui->label->setPalette(label_palette);

Wherein QColor is R, G, B values corresponding to, RGB three-color table may refer to: https://www.sojson.com/rgb.html

2, combined with qss syntax directly modify the style

 1 ui->label->setStyleSheet("QLabel{background:#000000;}"); 

 

Conclusion: Proven, works both ways.

Guess you like

Origin www.cnblogs.com/malinzhai/p/12609281.html