Skip to content

Commit 339887e

Browse files
add-uosdeepin-bot[bot]
authored andcommitted
fix(viewing): replace font metrics with document renderer
Upgrade the height computation mechanism to utilize QTextDocument instead of QFontMetrics. This change accommodates HTML formatting in the license display and adjusts minimum dimensions to improve visual proportions across different content volumes. log: replace font metrics with document renderer pms: BUG-314073
1 parent 0051a98 commit 339887e

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

dde-license-dialog/src/content.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QtConcurrent>
2222
#include <QThread>
2323
#include <QTranslator>
24+
#include <QTextDocument>
2425

2526
#include <unistd.h>
2627

@@ -278,10 +279,11 @@ void Content::updateContent()
278279
// 根据文本多少,调整窗口大小
279280
void Content::updateWindowHeight()
280281
{
281-
QRect rc = m_source->rect();
282-
rc.setWidth(rc.width() - 40);
283-
QSize sz = m_source->fontMetrics().boundingRect(rc, Qt::TextWordWrap, m_source->text()).size();
284-
285-
int minHeight = qBound(300, sz.height(), 491);
282+
QTextDocument doc;
283+
doc.setHtml(m_source->text());
284+
doc.setTextWidth(m_scrollArea->width() - 40);
285+
286+
int contentHeight = static_cast<int>(doc.size().height());
287+
int minHeight = qBound(100, contentHeight, 491);
286288
m_scrollArea->setMinimumHeight(minHeight);
287289
}

0 commit comments

Comments
 (0)