增加默认窗口阴影效果

This commit is contained in:
lixueman 2022-10-12 11:03:51 +08:00
parent c960b12c38
commit 1b307497a2
2 changed files with 13 additions and 26 deletions

View File

@ -54,23 +54,12 @@ void MainViewWidget::styleChangeSlot(const QString &style)
void MainViewWidget::paintEvent(QPaintEvent *event)
{
// double transparency = getTransparency();
QRect rect = this->rect();
QRect rect = this->rect().adjusted(5, 5, 0, -5);
QPainterPath path;
QPainter painter(this);
path.addRoundedRect(rect, 10, 10);
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
painter.setPen(Qt::transparent);
qreal radius = 10;
path.moveTo(rect.topRight() - QPointF(radius, 0));
path.lineTo(rect.topLeft() + QPointF(radius, 0));
path.quadTo(rect.topLeft(), rect.topLeft() + QPointF(0, radius));
path.lineTo(rect.bottomLeft() + QPointF(0, -radius));
path.quadTo(rect.bottomLeft(), rect.bottomLeft() + QPointF(radius, 0));
path.lineTo(rect.bottomRight() - QPointF(radius, 0));
path.quadTo(rect.bottomRight(), rect.bottomRight() + QPointF(0, -radius));
path.lineTo(rect.topRight() + QPointF(0, radius));
path.quadTo(rect.topRight(), rect.topRight() + QPointF(-radius, -0));
painter.setPen(Qt::transparent);
painter.setOpacity(0.58);
painter.fillPath(path, m_backColor);
QWidget::paintEvent(event);

View File

@ -674,28 +674,26 @@ void MainWindow::paintEvent(QPaintEvent *event)
if ( transparency == 1) {
curColor.setAlpha(255);
}
QRect rect = this->rect();
QRect rect = this->rect().adjusted(5, 5, -5, -5);
QPainterPath path;
// rect.setTopLeft(QPoint(rect.x()+320,rect.y()));
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
painter.save();
painter.setPen(Qt::transparent);
qreal radius = 10;
path.moveTo(rect.topRight() - QPointF(radius, 0));
path.lineTo(rect.topLeft() + QPointF(radius, 0));
path.quadTo(rect.topLeft(), rect.topLeft() + QPointF(0, radius));
path.lineTo(rect.bottomLeft() + QPointF(0, -radius));
path.quadTo(rect.bottomLeft(), rect.bottomLeft() + QPointF(radius, 0));
path.lineTo(rect.bottomRight() - QPointF(radius, 0));
path.quadTo(rect.bottomRight(), rect.bottomRight() + QPointF(0, -radius));
path.lineTo(rect.topRight() + QPointF(0, radius));
path.quadTo(rect.topRight(), rect.topRight() + QPointF(-radius, -0));
path.addRoundedRect(rect, 10, 10);
painter.setBrush(curColor);
painter.setPen(Qt::transparent);
painter.setOpacity(transparency);
painter.drawPath(path);
KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
QMainWindow::paintEvent(event);
QColor color = Qt::black;
for (int i = 0; i < 6; i++) {
rect = this->rect().adjusted(i, i, - i, - i);
color.setAlpha(i * 6);
painter.setBrush(Qt::NoBrush);
painter.setPen(QPen(color, 1));
painter.drawRoundedRect(rect, 10, 10);
}
}
/**
*