From 5ff60b1e8648cfef056af51f1ae28d70e8c36974 Mon Sep 17 00:00:00 2001 From: Linloir <3145078758@qq.com> Date: Sat, 17 Dec 2022 11:41:41 +0800 Subject: [PATCH] [UI][FIX] Fix color name in style sheet --- FinalProject/roundedcornerwidget.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/FinalProject/roundedcornerwidget.cpp b/FinalProject/roundedcornerwidget.cpp index f605d79..2f076fa 100644 --- a/FinalProject/roundedcornerwidget.cpp +++ b/FinalProject/roundedcornerwidget.cpp @@ -38,7 +38,7 @@ void RoundedCornerWidget::initializeWidgetUI() { _borderWidget = new QWidget(this); _borderWidget->setObjectName("borderWidget"); QString borderWidgetStyleSheet = - "QWidget#borderWidget{background-color:#00FFFFFF;border:2px solid " + _borderColor.name() + ";" + "QWidget#borderWidget{background-color:#00FFFFFF;border:2px solid " + _borderColor.name(QColor::HexArgb) + ";" "border-radius:" + QString::number(_cornerRadius) + "px;}"; _borderWidget->setStyleSheet(borderWidgetStyleSheet); _borderWidget->setAttribute(Qt::WA_TransparentForMouseEvents); @@ -74,10 +74,12 @@ void RoundedCornerWidget::setCornerRadius(int radius) { _cornerRadius = radius; // Modify the corner radius in the current style sheet of the border widget - QString styleSheet = _borderWidget->styleSheet(); - styleSheet.replace(QRegularExpression("border-radius:\\d+px;"), - QString("border-radius:%1px;").arg(_cornerRadius)); - _borderWidget->setStyleSheet(styleSheet); + if (_borderWidget != nullptr) { + QString styleSheet = _borderWidget->styleSheet(); + styleSheet.replace(QRegularExpression("border-radius:\\d+px;"), + QString("border-radius:%1px;").arg(_cornerRadius)); + _borderWidget->setStyleSheet(styleSheet); + } // Reset the mask of the main widget QPainterPath path; @@ -91,10 +93,12 @@ void RoundedCornerWidget::setBorderColor(QColor color) { _borderColor = color; // Modify the border color in the current style sheet of the border widget - QString styleSheet = _borderWidget->styleSheet(); - styleSheet.replace(QRegularExpression("border:2px solid #\\w+;"), - QString("border:2px solid %1;").arg(_borderColor.name())); - _borderWidget->setStyleSheet(styleSheet); + if (_borderWidget != nullptr) { + QString styleSheet = _borderWidget->styleSheet(); + styleSheet.replace(QRegularExpression("border:2px solid #\\w+;"), + QString("border:2px solid %1;").arg(_borderColor.name(QColor::HexArgb))); + _borderWidget->setStyleSheet(styleSheet); + } } QWidget* RoundedCornerWidget::mainWidget() const {