linning-blog

将窗口设置为透明(setAttribute(Qt::WA_TranslucentBackground);)

然后重载paintEvent:

void MyWidget::paintEvent(QPaintEvent *event)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRect(10, 10, this->width() - 20, this->height() - 20);

QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.fillPath(path, QBrush(Qt::white));

QColor color(0, 0, 0, 50);
for (int i = 0; i < 10; i++)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRect(10 - i, 10 - i, this->width() - (10 - i) * 2, this->height() - (10 - i) * 2);
color.setAlpha(150 - qSqrt(i) * 50);
painter.setPen(color);
painter.drawPath(path);
}
}

分类:

技术点:

相关文章:

  • 2021-12-26
  • 2021-12-26
  • 2021-12-26
  • 2021-09-13
  • 2021-12-26
  • 2021-12-26
  • 2021-12-26
  • 2021-12-14
猜你喜欢
  • 2021-08-17
  • 2021-10-06
  • 2021-12-26
  • 2021-10-30
  • 2021-12-26
  • 2021-10-25
  • 2021-11-04
相关资源
相似解决方案