From bd90c1b701480eaae397cb56b9fef0db9fcfa3de Mon Sep 17 00:00:00 2001 From: lixueman Date: Wed, 20 Jul 2022 13:41:26 +0800 Subject: [PATCH] =?UTF-8?q?#130526,=E4=BF=AE=E6=94=B9=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=A1=86=E5=92=8C=E6=94=B6=E8=97=8F=E6=9C=80=E8=BF=91=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E9=AB=98=E4=BA=AE=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UserInterface/full_mainwindow.cpp | 14 +++++++---- src/UserInterface/mainwindow.cpp | 35 ++++++++++++++------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/UserInterface/full_mainwindow.cpp b/src/UserInterface/full_mainwindow.cpp index 3c77fd5..3ccb33f 100755 --- a/src/UserInterface/full_mainwindow.cpp +++ b/src/UserInterface/full_mainwindow.cpp @@ -3,6 +3,7 @@ #include #include #include "utility.h" +#include FullMainWindow::FullMainWindow(QWidget *parent) : QMainWindow(parent) @@ -290,12 +291,15 @@ bool FullMainWindow::eventFilter(QObject *watched, QEvent *event) { if (watched == m_lineEdit) { m_isSearching = true; - char style[200]; + QString style; if (event->type() == QEvent::FocusIn) { - sprintf(style, "QLineEdit{border:2px solid %s;background-color:%s;border-radius:17px;color:#ffffff;}", - QueryLineEditClickedBorder, QueryLineEditClickedBackground); + QString highLightColor = QString::number(m_lineEdit->palette().color(QPalette::Highlight).rgba(), 16); + QString color = highLightColor.mid(2, 6); + style = QString("QLineEdit{border:2px solid #%1;background-color:%2;border-radius:17px;color:#ffffff;}") + .arg(color).arg(QueryLineEditClickedBackground); m_lineEdit->setStyleSheet(style); + myDebug() <text().isEmpty()) { qDebug() << "bool FullMainWindow::eventFilter(QObject *watched, QEvent *event)" << m_queryWid->layout()->count(); @@ -310,8 +314,8 @@ bool FullMainWindow::eventFilter(QObject *watched, QEvent *event) m_lineEdit->setTextMargins(26, 0, 0, 0); } } else if (event->type() == QEvent::FocusOut && m_lineEdit->text().isEmpty()) { - sprintf(style, "QLineEdit{border:1px solid %s;background-color:%s;border-radius:17px;color:#ffffff;}", - QueryLineEditClickedBorderDefault, QueryLineEditClickedBackground); + style = QString("QLineEdit{border:1px solid %1;background-color:%2;border-radius:17px;color:#ffffff;}") + .arg(QueryLineEditClickedBorderDefault).arg(QueryLineEditClickedBackground); m_lineEdit->setStyleSheet(style); resetEditline(); } diff --git a/src/UserInterface/mainwindow.cpp b/src/UserInterface/mainwindow.cpp index 1f09418..cc67dcb 100755 --- a/src/UserInterface/mainwindow.cpp +++ b/src/UserInterface/mainwindow.cpp @@ -33,6 +33,7 @@ #include #include #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -316,7 +317,10 @@ void MainWindow::initSearchUi() m_leftTopSearchHorizontalLayout->setContentsMargins(8, 0, 8, 0); m_lineEdit = new QLineEdit(m_minSearchPage); m_lineEdit->setMinimumSize(QSize(30, 26)); - m_lineEdit->setStyleSheet(QString::fromUtf8("border-radius: 13px; border:1px solid rgba(5, 151, 255, 1); background: transparent;")); + QString highLightColor = QString::number(m_lineEdit->palette().color(QPalette::Highlight).rgba(), 16); + QString color = highLightColor.mid(2, 6); + QString searchStyle = QString("border-radius: 13px; border:1px solid #%1; background: transparent;").arg(color); + m_lineEdit->setStyleSheet(searchStyle); m_lineEdit->setFrame(false); m_lineEdit->setPlaceholderText(tr("Search")); m_lineEdit->installEventFilter(this); @@ -519,7 +523,7 @@ void MainWindow::windowOption() void MainWindow::initUi() { qDebug() << "init UI"; - this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); + this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::BypassWindowManagerHint); this->setAttribute(Qt::WA_TranslucentBackground, true); this->setAutoFillBackground(false); this->setFocusPolicy(Qt::NoFocus); @@ -558,11 +562,10 @@ void MainWindow::initUi() m_dropDownMenu->addAction(m_letterAction); m_dropDownMenu->addAction(m_funcAction); m_allAction->setChecked(true); - m_collectPushButton->setStyleSheet("color:#3790FA;"); - QColor textColor = this->palette().color(QPalette::Text); - QRgb rgbDefault = qRgb(textColor.red(), textColor.green(), textColor.blue()); - QString textColorDefault = "#" + QString::number(rgbDefault, 16); - m_recentPushButton->setStyleSheet(QString("color:%1;").arg(textColorDefault)); + QString textColorHightLight = QString::number(this->palette().color(QPalette::Highlight).rgba(), 16).mid(2, 6); + m_collectPushButton->setStyleSheet(QString("color: #%1;").arg(textColorHightLight)); + QString textColorDefault = QString::number(this->palette().color(QPalette::Text).rgba(), 16).mid(2, 6); + m_recentPushButton->setStyleSheet(QString("color: #%1;").arg(textColorDefault)); QAction *action = new QAction(); action->setIcon(getCurIcon(":/data/img/mainviewwidget/DM-icon-search.svg", true)); m_lineEdit->addAction(action, QLineEdit::LeadingPosition); @@ -1209,13 +1212,12 @@ void MainWindow::on_collectPushButton_clicked() { m_rightStackedWidget->setCurrentIndex(0); - m_collectPushButton->setStyleSheet("color:#3790FA;"); + QString textColorHightLight = QString::number(this->palette().color(QPalette::Highlight).rgba(), 16).mid(2, 6); + m_collectPushButton->setStyleSheet(QString("color:#%1;").arg(textColorHightLight)); QFont collectFont(QGuiApplication::font().family(), QGuiApplication::font().pointSize() + 2); m_collectPushButton->setFont(collectFont); - QColor textColor = this->palette().color(QPalette::Text); - QRgb rgbDefault = qRgb(textColor.red(), textColor.green(), textColor.blue()); - QString textColorDefault = "#" + QString::number(rgbDefault, 16); - m_recentPushButton->setStyleSheet(QString("color:%1;").arg(textColorDefault)); + QString textColorDefault = QString::number(this->palette().color(QPalette::Text).rgba(), 16).mid(2, 6); + m_recentPushButton->setStyleSheet(QString("color:#%1;").arg(textColorDefault)); QFont recentFont(QGuiApplication::font().family(), QGuiApplication::font().pointSize()); m_recentPushButton->setFont(recentFont); } @@ -1223,13 +1225,12 @@ void MainWindow::on_collectPushButton_clicked() void MainWindow::on_recentPushButton_clicked() { m_rightStackedWidget->setCurrentIndex(1); - QColor textColor = this->palette().color(QPalette::Text); - QRgb rgbDefault = qRgb(textColor.red(), textColor.green(), textColor.blue()); - QString textColorDefault = "#" + QString::number(rgbDefault, 16); - m_collectPushButton->setStyleSheet(QString("color:%1").arg(textColorDefault)); + QString textColorDefault = QString::number(this->palette().color(QPalette::Text).rgba(), 16).mid(2, 6); + m_collectPushButton->setStyleSheet(QString("color:#%1").arg(textColorDefault)); QFont collectFont(QGuiApplication::font().family(), QGuiApplication::font().pointSize()); m_collectPushButton->setFont(collectFont); - m_recentPushButton->setStyleSheet("color:#3790FA"); + QString textColorHightLight = QString::number(this->palette().color(QPalette::Highlight).rgba(), 16).mid(2, 6); + m_recentPushButton->setStyleSheet(QString("color:#%1").arg(textColorHightLight)); QFont recentFont(QGuiApplication::font().family(), QGuiApplication::font().pointSize() + 2); m_recentPushButton->setFont(recentFont);