From 070540fae006ef14ba560a80f7acec613030a841 Mon Sep 17 00:00:00 2001 From: jianglinxuan Date: Wed, 6 May 2020 14:28:43 +0800 Subject: [PATCH] Modify the method of drawing the window box border * White lines appear at rounded corners when drawing translucent borders using QSS * The current use of self-painted border lines --- src/ukws_window_box.cpp | 32 ++++++++++++++++++++++++++------ src/ukws_window_box.h | 2 ++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/ukws_window_box.cpp b/src/ukws_window_box.cpp index 004cfe4..3079e9f 100644 --- a/src/ukws_window_box.cpp +++ b/src/ukws_window_box.cpp @@ -54,6 +54,7 @@ UkwsWindowBox::UkwsWindowBox(QWidget *parent) : QWidget(parent) frameXid = 0; hasFrame = false; drag = nullptr; + isSelected = false; titleAutoHide = false; titleLabel = new UkwsWindowExtraLabel(); @@ -162,6 +163,27 @@ void UkwsWindowBox::paintEvent(QPaintEvent *event) QPainter painter(this); style()->drawPrimitive(QStyle::PE_Widget, &styleOpt, &painter, this); + if (isSelected) { + QSize size = this->size(); + + // 获取圆角边框区域 + QRectF rect; + QPainterPath path; + + rect = QRectF(UKWS_WINDOWBOX_BORDER, UKWS_WINDOWBOX_BORDER, + size.width() - UKWS_WINDOWBOX_BORDER * 2, + size.height() - UKWS_WINDOWBOX_BORDER * 2); + path.addRoundedRect(rect, UKWS_THUMBNAIL_RADIUS, UKWS_THUMBNAIL_RADIUS); + rect = QRectF(0, 0, size.width(), size.height()); + path.addRoundedRect(rect, UKWS_THUMBNAIL_RADIUS + UKWS_WINDOWBOX_BORDER, + UKWS_THUMBNAIL_RADIUS + UKWS_WINDOWBOX_BORDER); + + painter.setRenderHint(QPainter::Antialiasing, false); + painter.setBrush(QBrush(QColor(255, 255, 255, 128))); + painter.setPen(QPen(QColor(255, 255, 255, 0))); + painter.drawPath(path); + } + QWidget::paintEvent(event); } @@ -456,16 +478,14 @@ void UkwsWindowBox::setThumbnailNormal() void UkwsWindowBox::setWindowBoxSelected() { - this->setStyleSheet("QWidget#winbox{padding:0px;" - "border:4px solid rgb(255, 255, 255, 127);" - "border-radius: 6px;}"); + isSelected = true; + update(); } void UkwsWindowBox::setWindowBoxUnselected() { - this->setStyleSheet("QWidget#winbox{padding:0px;" - "border:4px solid rgb(255, 255, 255, 0);" - "border-radius: 6px;}"); + isSelected = false; + update(); } void UkwsWindowBox::setTitleAutoHide(bool autoHide) diff --git a/src/ukws_window_box.h b/src/ukws_window_box.h index 4d70559..feb6a4b 100644 --- a/src/ukws_window_box.h +++ b/src/ukws_window_box.h @@ -157,6 +157,8 @@ public slots: WnckWindow *wnckWin; bool hasFrame; + bool isSelected; + QDrag *drag; QSize dragIconSize; QTimer scaleTimer;