From 5141141e4fe8edeba5caeeb663838be2fc662639 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Thu, 29 Jan 2026 19:54:34 +0800 Subject: [PATCH] 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 --- dde-license-dialog/src/content.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dde-license-dialog/src/content.cpp b/dde-license-dialog/src/content.cpp index 4d8bb05f..a1e3c64d 100644 --- a/dde-license-dialog/src/content.cpp +++ b/dde-license-dialog/src/content.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -278,10 +279,11 @@ void Content::updateContent() // 根据文本多少,调整窗口大小 void Content::updateWindowHeight() { - QRect rc = m_source->rect(); - rc.setWidth(rc.width() - 40); - QSize sz = m_source->fontMetrics().boundingRect(rc, Qt::TextWordWrap, m_source->text()).size(); - - int minHeight = qBound(300, sz.height(), 491); + QTextDocument doc; + doc.setHtml(m_source->text()); + doc.setTextWidth(m_scrollArea->width() - 40); + + int contentHeight = static_cast(doc.size().height()); + int minHeight = qBound(100, contentHeight, 491); m_scrollArea->setMinimumHeight(minHeight); }