SimpleDao
Qt设置渐变背景
2019-05-06, 访问数: 1131

qss

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

widget

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