Qt设置渐变背景

qss

1
background-color: qlineargradient(spread:repeat, x1: 0, y1: 0, x2: 0, y2: 1, stop: 0#2ba0d6, stop: 1 #138abd);

widget

1
2
3
4
5
6
7
8
QLinearGradient linearGradient(0, 0, 0, 300);
linearGradient.setColorAt(0.0, Qt::green);
linearGradient.setColorAt(1.0, Qt::blue);
QPalette pal;
pal.setBrush(QPalette::Window, QBrush(linearGradient));
//设置背景自动填充
ui->widget->setAutoFillBackground(true);
ui->widget->setPalette(pal);
文章目录
  1. 1. qss
  2. 2. widget