From 83865c93ded6e67a84702b3eaa1d705cd510e319 Mon Sep 17 00:00:00 2001 From: heyuming Date: Wed, 22 Mar 2023 15:06:12 +0800 Subject: [PATCH] fix: set limit width to textLabel to correct text elide behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Log: 设置宽度限制以纠正文本省略行为 --- plugins/pluginmanager/standardquickitem.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/pluginmanager/standardquickitem.cpp b/plugins/pluginmanager/standardquickitem.cpp index 1be3d9aff..9e18af0de 100644 --- a/plugins/pluginmanager/standardquickitem.cpp +++ b/plugins/pluginmanager/standardquickitem.cpp @@ -95,11 +95,11 @@ QWidget *StandardQuickItem::iconWidget(QWidget *parent) QLabel *labelText = new QLabel(widget); labelText->setObjectName("textLabel"); - labelText->setFixedHeight(TEXTHEIGHT); - labelText->setFixedWidth(this->width()); - updatePluginName(labelText); labelText->setAlignment(Qt::AlignCenter); labelText->setFont(DFontSizeManager::instance()->t10()); + labelText->setFixedHeight(TEXTHEIGHT); + labelText->setFixedWidth(70); + updatePluginName(labelText); layout->addWidget(imageLabel); layout->addSpacing(7); layout->addWidget(labelText); @@ -157,13 +157,14 @@ void StandardQuickItem::updatePluginName(QLabel *textLabel) if (text.isEmpty()) text = pluginItem()->pluginDisplayName(); QFontMetrics ftm(textLabel->font()); - if (ftm.boundingRect(text).width() > textLabel->width()) { + if (ftm.boundingRect(text).width() > 70) { this->setToolTip(text); } else { this->setToolTip(""); } - text = ftm.elidedText(text, Qt::TextElideMode::ElideMiddle, textLabel->width()); + text = ftm.elidedText(text, Qt::TextElideMode::ElideMiddle, 70); textLabel->setText(text); + qInfo() << "text update to: " << text; } void StandardQuickItem::doUpdate()