From addd20b76ac43f7c0a9ec7e912db54531168cffc Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Wed, 26 Nov 2025 18:24:24 +0800 Subject: [PATCH] fix: should also update geometry when tips type changed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 目前在 tips 控件的类型(单行/多行)变化时,若原本控件内存储的文案没有 变化,则不一定会重新计算界面宽度.此提交新增了类型变化的检查. PMS: BUG-335551 Log: --- plugins/dde-dock/bluetooth/bluetoothitem.cpp | 3 --- plugins/dde-dock/widgets/tipswidget.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/dde-dock/bluetooth/bluetoothitem.cpp b/plugins/dde-dock/bluetooth/bluetoothitem.cpp index 129c0fc1f..6cf98dcdf 100644 --- a/plugins/dde-dock/bluetooth/bluetoothitem.cpp +++ b/plugins/dde-dock/bluetooth/bluetoothitem.cpp @@ -189,9 +189,6 @@ void BluetoothItem::refreshTips() } m_tipsLabel->setText(tipsText); - QFontMetrics metrics(m_tipsLabel->font()); - int textWidth = metrics.boundingRect(m_tipsLabel->text()).width(); - m_tipsLabel->setMinimumWidth(textWidth); m_quickPanel->setDescription(description); } diff --git a/plugins/dde-dock/widgets/tipswidget.cpp b/plugins/dde-dock/widgets/tipswidget.cpp index 122944b98..6ff7fb121 100644 --- a/plugins/dde-dock/widgets/tipswidget.cpp +++ b/plugins/dde-dock/widgets/tipswidget.cpp @@ -19,6 +19,7 @@ TipsWidget::TipsWidget(QWidget *parent) void TipsWidget::setText(const QString &text) { + bool typeChanged = m_type != TipsWidget::SingleLine; m_type = TipsWidget::SingleLine; // 如果传递的是富文本,获取富文本中的纯文本内容进行显示 QTextDocument document; @@ -26,6 +27,10 @@ void TipsWidget::setText(const QString &text) // 同时去掉两边的空白信息,例如qBittorrent的提示 QString newText = document.toPlainText().simplified(); if (m_text == newText) { + if (typeChanged) { + updateGeometry(); + update(); + } return; } @@ -50,8 +55,13 @@ void TipsWidget::setText(const QString &text) void TipsWidget::setTextList(const QStringList &textList) { + bool typeChanged = m_type != TipsWidget::MultiLine; m_type = TipsWidget::MultiLine; if (textList == m_textList) { + if (typeChanged) { + updateGeometry(); + update(); + } return; } m_textList = textList;