托盘 密码框开关按钮适配半透明

This commit is contained in:
zhangyuanyuan1 2022-10-26 16:00:08 +08:00 committed by jzxc95
parent e5c1d7e498
commit dd8ae3a3b6
4 changed files with 22 additions and 28 deletions

View File

@ -51,7 +51,6 @@ WlanListItem::WlanListItem(KyWirelessNetItem &wirelessNetItem, QString device, Q
connect(this->m_infoButton, &InfoButton::clicked, this, &WlanListItem::onInfoButtonClicked);
connect(m_menu, &QMenu::triggered, this, &WlanListItem::onMenuTriggered);
connect(qApp, &QApplication::paletteChanged, this, &WlanListItem::setConnectButtonState);
m_wirelessConnectOperation = new KyWirelessConnectOperation(this);
m_deviceResource = new KyNetworkDeviceResourse(this);
@ -242,6 +241,16 @@ void WlanListItem::keyPressEvent(QKeyEvent *event)
return QFrame::keyPressEvent(event);
}
void WlanListItem::paintEvent(QPaintEvent *event)
{
QPalette pal = qApp->palette();
if (m_pwdLineEdit != nullptr) {
m_pwdLineEdit->setPalette(pal);
}
return QWidget::paintEvent(event);
}
void WlanListItem::initWlanUI()
{
m_hasPwd = (m_wirelessNetItem.m_secuType.isEmpty() || m_wirelessNetItem.m_secuType == "") ? false : true;
@ -268,6 +277,8 @@ void WlanListItem::initWlanUI()
m_pwdLineEdit = new KPasswordEdit(m_pwdFrame);
m_pwdLineEdit->setFixedWidth(LINEEDIT_WIDTH);
m_pwdLineEdit->setProperty("needTranslucent", true);
m_pwdLineEdit->setUseCustomPalette(true);
m_pwdLineEdit->setClearButtonEnabled(false); //禁用ClearBtn按钮
m_pwdLineEdit->setAttribute(Qt::WA_InputMethodEnabled, true); //打开输入法
// m_pwdLineEdit->setAttribute(Qt::WA_InputMethodEnabled, false);
@ -283,6 +294,7 @@ void WlanListItem::initWlanUI()
m_pwdFrameLyt->addWidget(m_pwdLineEdit);
m_connectButton = new QPushButton(m_pwdFrame);
m_connectButton->setProperty("isImportant", true);
m_connectButton->setProperty("needTranslucent", true);
m_connectButton->setFixedSize(CONNECT_BUTTON_WIDTH, PWD_AREA_HEIGHT);
m_connectButton->setText(tr("Connect"));
@ -555,7 +567,6 @@ void WlanListItem::onPwdEditorTextChanged()
} else {
m_connectButton->setEnabled(true);
}
setConnectButtonState();
return;
}
@ -653,16 +664,3 @@ void WlanListItem::forgetPwd()
return;
}
}
void WlanListItem::setConnectButtonState()
{
QPalette btnPal;
if (m_connectButton->isEnabled()) {
btnPal.setColor(QPalette::Button, ENABLE_BUTTON_COLOR);
btnPal.setColor(QPalette::ButtonText, Qt::white);
m_connectButton->setPalette(btnPal);
} else {
btnPal.setColor(QPalette::Button, UNABLE_BUTTON_COLOR);
m_connectButton->setPalette(btnPal);
}
}

View File

@ -86,6 +86,7 @@ protected:
void leaveEvent(QEvent *event);
bool eventFilter(QObject *watched, QEvent *event);
void keyPressEvent(QKeyEvent *event);
void paintEvent(QPaintEvent *event);
Q_SIGNALS:
void itemHeightChanged(const bool isExpanded, const QString &ssid);
@ -132,7 +133,6 @@ private Q_SLOTS:
void onConnectButtonClicked();
void onMenuTriggered(QAction *action);
void onEnterpriseWlanDialogClose(bool isShow);
void setConnectButtonState();
};
#endif // WLANLISTITEM_H

View File

@ -73,6 +73,10 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent)
connect(m_wiredConnectOperation, &KyWiredConnectOperation::activateConnectionError, this, &LanPage::activateFailed);
connect(m_wiredConnectOperation, &KyWiredConnectOperation::deactivateConnectionError, this, &LanPage::deactivateFailed);
connect(m_wiredConnectOperation, &KyWiredConnectOperation::wiredEnabledChanged, this, &LanPage::onWiredEnabledChanged);
connect(m_netSwitch, &KSwitchButton::clicked, this, [=](bool checked) {
m_netSwitch->setChecked(!checked);
m_wiredConnectOperation->setWiredEnabled(checked);
});
}
LanPage::~LanPage()
@ -1188,16 +1192,7 @@ bool LanPage::eventFilter(QObject *watched, QEvent *event)
this->showDesktopNotify(tr("No ethernet device avaliable"), "networkwrong");
m_netSwitch->setChecked(false);
m_netSwitch->setCheckable(false);
} else {
m_netSwitch->setCheckable(true);
// if (m_netSwitch->isChecked()) {
// m_switchGsettings->set(WIRED_SWITCH, false);
// } else {
// m_switchGsettings->set(WIRED_SWITCH,true);
// }
m_wiredConnectOperation->setWiredEnabled(!m_netSwitch->isChecked());
}
return true;
}
}

View File

@ -78,6 +78,10 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::wifiEnabledChanged, this, &WlanPage::onWifiEnabledChanged);
connect(m_connectResource, &KyConnectResourse::connectivityChanged, this, &WlanPage::connectivityChanged);
connect(m_netSwitch, &KSwitchButton::clicked, this, [=](bool checked) {
m_netSwitch->setChecked(!checked);
setWirelessEnable(checked);
});
}
bool WlanPage::eventFilter(QObject *w, QEvent *e)
@ -93,10 +97,7 @@ bool WlanPage::eventFilter(QObject *w, QEvent *e)
if (!getSwitchBtnEnable()) {
showDesktopNotify(tr("No wireless network card detected"), "networkwrong");
//检测不到无线网卡不再触发click信号
} else {
setWirelessEnable(!getSwitchBtnState());
}
return true;
}
}
return QWidget::eventFilter(w,e);