forked from openkylin/ukui-menu
增加默认窗口阴影效果
This commit is contained in:
parent
c960b12c38
commit
1b307497a2
|
@ -54,23 +54,12 @@ void MainViewWidget::styleChangeSlot(const QString &style)
|
||||||
|
|
||||||
void MainViewWidget::paintEvent(QPaintEvent *event)
|
void MainViewWidget::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
// double transparency = getTransparency();
|
QRect rect = this->rect().adjusted(5, 5, 0, -5);
|
||||||
QRect rect = this->rect();
|
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
path.addRoundedRect(rect, 10, 10);
|
||||||
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
||||||
painter.setPen(Qt::transparent);
|
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.setOpacity(0.58);
|
||||||
painter.fillPath(path, m_backColor);
|
painter.fillPath(path, m_backColor);
|
||||||
QWidget::paintEvent(event);
|
QWidget::paintEvent(event);
|
||||||
|
|
|
@ -674,28 +674,26 @@ void MainWindow::paintEvent(QPaintEvent *event)
|
||||||
if ( transparency == 1) {
|
if ( transparency == 1) {
|
||||||
curColor.setAlpha(255);
|
curColor.setAlpha(255);
|
||||||
}
|
}
|
||||||
QRect rect = this->rect();
|
QRect rect = this->rect().adjusted(5, 5, -5, -5);
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
// rect.setTopLeft(QPoint(rect.x()+320,rect.y()));
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
||||||
|
painter.save();
|
||||||
painter.setPen(Qt::transparent);
|
painter.setPen(Qt::transparent);
|
||||||
qreal radius = 10;
|
path.addRoundedRect(rect, 10, 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.setBrush(curColor);
|
painter.setBrush(curColor);
|
||||||
painter.setPen(Qt::transparent);
|
painter.setPen(Qt::transparent);
|
||||||
painter.setOpacity(transparency);
|
painter.setOpacity(transparency);
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 鼠标点击窗口外部事件
|
* 鼠标点击窗口外部事件
|
||||||
|
|
Loading…
Reference in New Issue