做边框修改

This commit is contained in:
zhaominyong 2022-02-23 12:10:39 +08:00
parent f029c195fd
commit 00c23c6617
3 changed files with 36 additions and 31 deletions

View File

@ -5,6 +5,7 @@
#include <QPainter>
#include <QApplication>
#include "imageutil.h"
#include "../gsettingswrapper.h"
MyIconButton::MyIconButton(QWidget *parent) :
QPushButton(parent)
@ -12,7 +13,7 @@ MyIconButton::MyIconButton(QWidget *parent) :
this->setCheckable(false);
m_iconButton = new QPushButton(this);
m_iconButton->setCheckable(false);
m_iconButton->setCheckable(true);
m_iconButton->setFixedSize(QSize(24, 24));
m_iconButton->setFocusPolicy(Qt::NoFocus);
m_iconButton->setFlat(true);
@ -32,13 +33,6 @@ MyIconButton::MyIconButton(QWidget *parent) :
setLayout(hLayout);
connect(m_iconButton, &QPushButton::clicked, this, &MyIconButton::click);
// connect(this, &QPushButton::toggled, this, [=] (bool checked) {
// if (checked)
// m_textLabel->setStyleSheet("color:white");
// else
// m_textLabel->setStyleSheet("color:palette(windowText)");
// });
connect(this, &QPushButton::toggled, this, &MyIconButton::changePalette);
}
MyIconButton::~MyIconButton()
@ -61,16 +55,26 @@ void MyIconButton::setDesplayText(const QString &text)
void MyIconButton::changePalette(bool checked)
{
// m_iconButton->setChecked(checked);
QPalette pal(m_textLabel->palette());
m_iconButton->setChecked(checked);
QPalette pal = m_textLabel->palette();
QIcon icon = QIcon::fromTheme(m_themeIconName, QIcon(m_defaultIconName));
QPixmap pix;
if (checked) {
pal.setColor(QPalette::ButtonText, pal.color(QPalette::HighlightedText));
pix = ImageUtil::loadPixmap(icon, QString("white"));
if (g_GSettingWrapper.isDarkTheme()) {
if (checked) {
pal.setColor(QPalette::ButtonText, this->palette().highlightedText().color());
pix = ImageUtil::loadPixmap(icon, QString("black"));
} else {
pal.setColor(QPalette::ButtonText, this->palette().windowText().color());
pix = ImageUtil::loadPixmap(icon, QString("white"));
}
} else {
pal.setColor(QPalette::ButtonText, pal.color(QPalette::WindowText));
pix = ImageUtil::loadPixmap(icon, QString("default"));
if (checked) {
pal.setColor(QPalette::ButtonText, this->palette().highlightedText().color());
pix = ImageUtil::loadPixmap(icon, QString("white"));
} else {
pal.setColor(QPalette::ButtonText, this->palette().windowText().color());
pix = ImageUtil::loadPixmap(icon, QString("black"));
}
}
m_textLabel->setPalette(pal);
m_iconButton->setIcon(pix);
@ -79,6 +83,7 @@ void MyIconButton::changePalette(bool checked)
void MyIconButton::paintEvent(QPaintEvent *event)
{
QPushButton::paintEvent(event);
changePalette(isChecked());
m_textLabel->setFixedWidth(this->width() - 38);
m_textLabel->setDeplayText(m_originalText);
}

View File

@ -56,18 +56,18 @@ void MyIconLabel::setDesplayText(const QString &text)
}
}
void MyIconLabel::changePalette(bool dark)
{
QPalette pal(m_textLabel->palette());
QIcon icon = QIcon::fromTheme(m_themeIconName, QIcon(m_defaultIconName));
QPixmap pix;
if (dark) {
pal.setColor(QPalette::WindowText, pal.color(QPalette::HighlightedText));
pix = ImageUtil::loadPixmap(icon, QString("white"));
} else {
pal.setColor(QPalette::WindowText, this->palette().color(QPalette::WindowText));
pix = ImageUtil::loadPixmap(icon, QString("default"));
}
m_textLabel->setPalette(pal);
m_iconLabel->setPixmap(pix);
}
//void MyIconLabel::changePalette(bool dark)
//{
// QPalette pal(m_textLabel->palette());
// QIcon icon = QIcon::fromTheme(m_themeIconName, QIcon(m_defaultIconName));
// QPixmap pix;
// if (dark) {
// pal.setColor(QPalette::WindowText, pal.color(QPalette::HighlightedText));
// pix = ImageUtil::loadPixmap(icon, QString("white"));
// } else {
// pal.setColor(QPalette::WindowText, this->palette().color(QPalette::WindowText));
// pix = ImageUtil::loadPixmap(icon, QString("default"));
// }
// m_textLabel->setPalette(pal);
// m_iconLabel->setPixmap(pix);
//}

View File

@ -15,7 +15,7 @@ public:
void setDesplayText(const QString &text);
public slots:
void changePalette(bool checked);
// void changePalette(bool checked);
private:
QLabel *m_iconLabel;