#130526,修改搜索框和收藏最近按钮高亮色

This commit is contained in:
lixueman 2022-07-20 13:41:26 +08:00
parent 3fa8df07e1
commit bd90c1b701
2 changed files with 27 additions and 22 deletions

View File

@ -3,6 +3,7 @@
#include <QAction>
#include <QTranslator>
#include "utility.h"
#include <QPalette>
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() <<color << style;
if (m_lineEdit->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();
}

View File

@ -33,6 +33,7 @@
#include <QGroupBox>
#include <QEventLoop>
#include <QLabel>
#include <QPalette>
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);