mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
fix: set limit width to textLabel to correct text elide behavior
Log: 设置宽度限制以纠正文本省略行为
This commit is contained in:
parent
9661d3568f
commit
83865c93de
@ -95,11 +95,11 @@ QWidget *StandardQuickItem::iconWidget(QWidget *parent)
|
|||||||
|
|
||||||
QLabel *labelText = new QLabel(widget);
|
QLabel *labelText = new QLabel(widget);
|
||||||
labelText->setObjectName("textLabel");
|
labelText->setObjectName("textLabel");
|
||||||
labelText->setFixedHeight(TEXTHEIGHT);
|
|
||||||
labelText->setFixedWidth(this->width());
|
|
||||||
updatePluginName(labelText);
|
|
||||||
labelText->setAlignment(Qt::AlignCenter);
|
labelText->setAlignment(Qt::AlignCenter);
|
||||||
labelText->setFont(DFontSizeManager::instance()->t10());
|
labelText->setFont(DFontSizeManager::instance()->t10());
|
||||||
|
labelText->setFixedHeight(TEXTHEIGHT);
|
||||||
|
labelText->setFixedWidth(70);
|
||||||
|
updatePluginName(labelText);
|
||||||
layout->addWidget(imageLabel);
|
layout->addWidget(imageLabel);
|
||||||
layout->addSpacing(7);
|
layout->addSpacing(7);
|
||||||
layout->addWidget(labelText);
|
layout->addWidget(labelText);
|
||||||
@ -157,13 +157,14 @@ void StandardQuickItem::updatePluginName(QLabel *textLabel)
|
|||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
text = pluginItem()->pluginDisplayName();
|
text = pluginItem()->pluginDisplayName();
|
||||||
QFontMetrics ftm(textLabel->font());
|
QFontMetrics ftm(textLabel->font());
|
||||||
if (ftm.boundingRect(text).width() > textLabel->width()) {
|
if (ftm.boundingRect(text).width() > 70) {
|
||||||
this->setToolTip(text);
|
this->setToolTip(text);
|
||||||
} else {
|
} else {
|
||||||
this->setToolTip("");
|
this->setToolTip("");
|
||||||
}
|
}
|
||||||
text = ftm.elidedText(text, Qt::TextElideMode::ElideMiddle, textLabel->width());
|
text = ftm.elidedText(text, Qt::TextElideMode::ElideMiddle, 70);
|
||||||
textLabel->setText(text);
|
textLabel->setText(text);
|
||||||
|
qInfo() << "text update to: " << text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardQuickItem::doUpdate()
|
void StandardQuickItem::doUpdate()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user