From bf3063f1500d1444126ee0cc888b99e9bae51668 Mon Sep 17 00:00:00 2001 From: FanPengCheng Date: Fri, 11 Jun 2021 13:55:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=93=9D=E7=89=99?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8A=96=E5=8A=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 只有一个蓝牙设备时,鼠标放上去滚动会抖动 Log: Bug: https://pms.uniontech.com/zentao/bug-view-81649.html Change-Id: I745bcca6b2b1b71c12c231db6af17172a551e009 --- .../componments/bluetoothadapteritem.cpp | 18 ++++++++++++++---- .../componments/bluetoothadapteritem.h | 1 - .../bluetooth/componments/bluetoothapplet.cpp | 7 ++++--- .../network/item/applet/accesspointwidget.cpp | 3 +-- .../item/applet/devicecontrolwidget.cpp | 3 +-- plugins/network/item/wireditem.cpp | 3 +-- plugins/network/networkitem.cpp | 18 ------------------ 7 files changed, 21 insertions(+), 32 deletions(-) diff --git a/plugins/bluetooth/componments/bluetoothadapteritem.cpp b/plugins/bluetooth/componments/bluetoothadapteritem.cpp index 6ddaa4043..ab5ed4ec7 100644 --- a/plugins/bluetooth/componments/bluetoothadapteritem.cpp +++ b/plugins/bluetooth/componments/bluetoothadapteritem.cpp @@ -182,8 +182,15 @@ void BluetoothAdapterItem::updateIconTheme(DGuiApplicationHelper::ColorType type QSize BluetoothAdapterItem::sizeHint() const { - return QSize(ItemWidth, m_deviceListview->model()->rowCount() * DeviceItemHeight - + (m_deviceListview->model()->rowCount() > 0 ? m_seperator->sizeHint().height() : 0));// 加上割线的高度 + int visualHeight = 0; + for (int i = 0; i < m_deviceListview->count(); i++) + visualHeight += m_deviceListview->visualRect(m_deviceModel->index(i, 0)).height(); + + int listMargin = m_deviceListview->contentsMargins().top() + m_deviceListview->contentsMargins().bottom(); + //显示声音设备列表高度 = 设备的高度 + 间隔 + 边距 + int viewHeight = visualHeight + m_deviceListview->spacing() * (m_deviceListview->count() - 1) + listMargin; + + return QSize(ItemWidth, m_adapterLabel->height() + (m_adapter->powered() ? m_seperator->sizeHint().height() + viewHeight : 0));// 加上分割线的高度 } int BluetoothAdapterItem::currentDeviceCount() @@ -283,16 +290,19 @@ void BluetoothAdapterItem::initUi() mainLayout->setContentsMargins(0, 0, 0, 0); m_deviceListview->setAccessibleName("DeviceItemList"); - m_deviceListview->setModel(m_deviceModel); - m_deviceListview->setItemSize(QSize(ItemWidth, DeviceItemHeight)); + m_deviceListview->setContentsMargins(0, 0, 0, 0); m_deviceListview->setBackgroundType(DStyledItemDelegate::ClipCornerBackground); m_deviceListview->setItemRadius(0); + m_deviceListview->setFrameShape(QFrame::NoFrame); m_deviceListview->setEditTriggers(QAbstractItemView::NoEditTriggers); m_deviceListview->setSelectionMode(QAbstractItemView::NoSelection); m_deviceListview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_deviceListview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_deviceListview->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); m_deviceListview->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + m_deviceListview->setItemSize(QSize(ItemWidth, DeviceItemHeight)); + m_deviceListview->setItemMargins(QMargins(0, 0, 0, 0)); + m_deviceListview->setModel(m_deviceModel); mainLayout->addWidget(m_adapterLabel); mainLayout->addWidget(m_seperator); diff --git a/plugins/bluetooth/componments/bluetoothadapteritem.h b/plugins/bluetooth/componments/bluetoothadapteritem.h index 3fd098ad4..f89e3c0bf 100644 --- a/plugins/bluetooth/componments/bluetoothadapteritem.h +++ b/plugins/bluetooth/componments/bluetoothadapteritem.h @@ -125,7 +125,6 @@ signals: private: void initData(); -// void setItemHoverColor(); void initUi(); void initConnect(); void setUnnamedDevicesVisible(bool isShow); diff --git a/plugins/bluetooth/componments/bluetoothapplet.cpp b/plugins/bluetooth/componments/bluetoothapplet.cpp index 940a2989b..60c4545b1 100644 --- a/plugins/bluetooth/componments/bluetoothapplet.cpp +++ b/plugins/bluetooth/componments/bluetoothapplet.cpp @@ -212,9 +212,9 @@ void BluetoothApplet::initUi() m_settingLabel->setFixedHeight(DeviceItemHeight); DFontSizeManager::instance()->bind(m_settingLabel->label(), DFontSizeManager::T7); - m_contentWidget->setContentsMargins(0, 0, 0, 0); m_contentLayout->setMargin(0); m_contentLayout->setSpacing(0); + m_contentLayout->setContentsMargins(0, 0, 0, 0); m_contentLayout->addWidget(m_seperator); m_contentLayout->addWidget(m_settingLabel, 0, Qt::AlignBottom | Qt::AlignVCenter); @@ -232,6 +232,7 @@ void BluetoothApplet::initUi() m_mainLayout->setMargin(0); m_mainLayout->setSpacing(0); + m_mainLayout->setContentsMargins(0, 0, 0, 0); m_mainLayout->addWidget(m_scroarea); updateSize(); } @@ -275,12 +276,12 @@ void BluetoothApplet::updateIconTheme() void BluetoothApplet::updateSize() { int height = 0; - height += TitleSpace; foreach (const auto item, m_adapterItems) { - height += TitleHeight; height += item->sizeHint().height(); } + height += m_seperator->height(); + // 加上蓝牙设置选项的高度 height += DeviceItemHeight; diff --git a/plugins/network/item/applet/accesspointwidget.cpp b/plugins/network/item/applet/accesspointwidget.cpp index 58a215ad1..2648d8615 100644 --- a/plugins/network/item/applet/accesspointwidget.cpp +++ b/plugins/network/item/applet/accesspointwidget.cpp @@ -43,7 +43,6 @@ DGUI_USE_NAMESPACE extern const QString DarkType; extern const QString LightType; -extern void initFontColor(QWidget *widget); AccessPointWidget::AccessPointWidget(QWidget *parent) : QFrame(parent) @@ -57,7 +56,7 @@ AccessPointWidget::AccessPointWidget(QWidget *parent) m_ssidBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); m_ssidBtn->setObjectName("Ssid"); - initFontColor(m_ssidBtn); + m_ssidBtn->setForegroundRole(QPalette::BrightText); bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType); diff --git a/plugins/network/item/applet/devicecontrolwidget.cpp b/plugins/network/item/applet/devicecontrolwidget.cpp index 46c4e7b20..15acf2e2d 100644 --- a/plugins/network/item/applet/devicecontrolwidget.cpp +++ b/plugins/network/item/applet/devicecontrolwidget.cpp @@ -36,7 +36,6 @@ DWIDGET_USE_NAMESPACE DGUI_USE_NAMESPACE extern const int ItemHeight = 30; -extern void initFontColor(QWidget *widget); DeviceControlWidget::DeviceControlWidget(QWidget *parent) : QWidget(parent) @@ -45,7 +44,7 @@ DeviceControlWidget::DeviceControlWidget(QWidget *parent) , m_loadingIndicator(new DLoadingIndicator(this)) { m_deviceName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - initFontColor(m_deviceName); + m_deviceName->setForegroundRole(QPalette::BrightText); const QPixmap pixmap = DHiDPIHelper::loadNxPixmap(":/wireless/resources/wireless/refresh.svg"); diff --git a/plugins/network/item/wireditem.cpp b/plugins/network/item/wireditem.cpp index 3edb21995..285dc8371 100644 --- a/plugins/network/item/wireditem.cpp +++ b/plugins/network/item/wireditem.cpp @@ -40,7 +40,6 @@ DGUI_USE_NAMESPACE const int ItemHeight = 36; extern const QString DarkType = "_dark.svg"; extern const QString LightType = ".svg"; -extern void initFontColor(QWidget *widget); WiredItem::WiredItem(WiredDevice *device, const QString &deviceName, QWidget *parent) : DeviceItem(device, parent) @@ -61,7 +60,7 @@ WiredItem::WiredItem(WiredDevice *device, const QString &deviceName, QWidget *pa m_connectedName->setText(m_deviceName); m_connectedName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - initFontColor(m_connectedName); + m_connectedName->setForegroundRole(QPalette::BrightText); auto connectionLayout = new QVBoxLayout(this); connectionLayout->setMargin(0); diff --git a/plugins/network/networkitem.cpp b/plugins/network/networkitem.cpp index 7f81891d3..2c9e8da6d 100644 --- a/plugins/network/networkitem.cpp +++ b/plugins/network/networkitem.cpp @@ -26,24 +26,6 @@ const QString MenueSettings = "settings"; #define TITLE_HEIGHT 46 #define ITEM_HEIGHT 36 -extern void initFontColor(QWidget *widget) -{ - if (!widget) - return; - - auto fontChange = [&](QWidget * widget) { - QPalette defaultPalette = widget->palette(); - defaultPalette.setBrush(QPalette::WindowText, defaultPalette.brightText()); - widget->setPalette(defaultPalette); - }; - - fontChange(widget); - - QObject::connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, widget, [ = ] { - fontChange(widget); - }); -} - NetworkItem::NetworkItem(QWidget *parent) : QWidget(parent) , m_tipsWidget(new Dock::TipsWidget(this))