From 36cb86cd6b6a3d18a49350640590264910ca6739 Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Thu, 15 Jun 2023 17:26:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=BB=A3=E7=90=86=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E5=8A=A0=E8=BD=BD=E5=BA=94=E7=94=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?setPixmap=E5=8D=A1=E9=A1=BF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/proxy/applistwidget.cpp | 20 +++++++++++++------- plugins/proxy/applistwidget.h | 5 +++-- plugins/proxy/proxy.cpp | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/plugins/proxy/applistwidget.cpp b/plugins/proxy/applistwidget.cpp index 450757c7..ab9d2fb2 100644 --- a/plugins/proxy/applistwidget.cpp +++ b/plugins/proxy/applistwidget.cpp @@ -43,12 +43,11 @@ void AppListWidget::setAppChecked(bool flag) /** * @brief AppListWidget::setAppIcon - * @param icon 应用图标的名称 + * @param icon 应用图标 */ -void AppListWidget::setAppIcon(const QPixmap &icon) +void AppListWidget::setAppIcon(const QIcon &icon) { - m_iconLabel->setAlignment(Qt::AlignCenter); - m_iconLabel->setPixmap(icon); + m_iconBtn->setIcon(icon); } /** @@ -119,12 +118,19 @@ void AppListWidget::initUI() mainLayout->setSpacing(8); m_checkBox = new QCheckBox(this); m_checkBox->setAttribute(Qt::WA_TransparentForMouseEvents, true); //m_checkBox不响应鼠标事件,将其传递给父窗口 - m_iconLabel = new QLabel(this); - m_iconLabel->setFixedSize(24, 24); + + m_iconBtn = new QToolButton(this); + m_iconBtn->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonIconOnly); + m_iconBtn->setAttribute(Qt::WA_TranslucentBackground, true); //透明 + m_iconBtn->setAttribute(Qt::WA_TransparentForMouseEvents, true); + m_iconBtn->setAutoRaise(true); + m_iconBtn->setFixedSize(24, 24); + m_iconBtn->setIconSize(QSize(24, 24)); + m_nameLabel = new QLabel(this); mainLayout->addWidget(m_checkBox); - mainLayout->addWidget(m_iconLabel); + mainLayout->addWidget(m_iconBtn); mainLayout->addWidget(m_nameLabel); mainLayout->addStretch(); } diff --git a/plugins/proxy/applistwidget.h b/plugins/proxy/applistwidget.h index 7c94e128..4c93bd91 100644 --- a/plugins/proxy/applistwidget.h +++ b/plugins/proxy/applistwidget.h @@ -28,6 +28,7 @@ #include #include #include +#include class AppListWidget : public QWidget { @@ -37,7 +38,7 @@ public: ~AppListWidget(); void setAppChecked(bool flag); - void setAppIcon(const QPixmap &icon); + void setAppIcon(const QIcon &icon); void setAppName(const QString &text); void onAppCheckStateChanged(); void AddAppProxyConfig(); @@ -51,7 +52,7 @@ private: void initDbus(); QCheckBox *m_checkBox = nullptr; - QLabel *m_iconLabel = nullptr; + QToolButton *m_iconBtn = nullptr; QLabel *m_nameLabel = nullptr; QString m_path = nullptr; QDBusInterface *m_dbusInterface = nullptr; diff --git a/plugins/proxy/proxy.cpp b/plugins/proxy/proxy.cpp index 31db8f82..c7996f7f 100644 --- a/plugins/proxy/proxy.cpp +++ b/plugins/proxy/proxy.cpp @@ -1227,7 +1227,7 @@ void Proxy::appListPadding() AppListWidget *appWidget = new AppListWidget(index, m_appListWidget); appWidget->setAppName(appInfo.value(0)); - appWidget->setAppIcon(QIcon::fromTheme(appInfo.value(1)).pixmap(24, 24)); + appWidget->setAppIcon(QIcon::fromTheme(appInfo.value(1))); appWidget->setAppChecked(flag); QListWidgetItem *appListWidgetItem = new QListWidgetItem(m_appListWidget);