From 4258dd5690755c529de6834d103759cbe7b6b00c Mon Sep 17 00:00:00 2001 From: songwentao Date: Thu, 20 Jan 2022 14:47:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E7=89=B9=E6=95=88=E5=85=B3=E9=97=AD=E5=90=8E=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A0=8F=E9=A2=84=E8=A7=88=E6=97=B6=E6=96=87=E5=AD=97=E6=88=AA?= =?UTF-8?q?=E6=96=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 激活窗口标题宽度计算错误 Log: Bug: https://pms.uniontech.com/zentao/bug-view-110343.html Influence: 任务栏-关闭窗口特效-预览时文字显示正常,标题过长时显示省略号 Change-Id: Idd948564d721398201555fa99fae483055b23b88 --- frame/item/components/appsnapshot.cpp | 2 +- frame/item/components/previewcontainer.cpp | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index f2349be25..d48f63fb4 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -182,7 +182,7 @@ void AppSnapshot::setWindowInfo(const WindowInfo &info) { m_windowInfo = info; QFontMetrics fm(m_title->font()); - QString strTtile = m_title->fontMetrics().elidedText(m_windowInfo.title, Qt::ElideRight, width() - m_closeBtn2D->width()); + QString strTtile = m_title->fontMetrics().elidedText(m_windowInfo.title, Qt::ElideRight, SNAP_WIDTH - SNAP_CLOSE_BTN_WIDTH - SNAP_CLOSE_BTN_MARGIN); m_title->setText(strTtile); updateTitle(); diff --git a/frame/item/components/previewcontainer.cpp b/frame/item/components/previewcontainer.cpp index 494fe14a6..43f0721be 100644 --- a/frame/item/components/previewcontainer.cpp +++ b/frame/item/components/previewcontainer.cpp @@ -185,19 +185,23 @@ void PreviewContainer::adjustSize(bool composite) count = qMin(count, screenWidth / SNAP_HEIGHT_WITHOUT_COMPOSITE); const int h = SNAP_HEIGHT_WITHOUT_COMPOSITE * count + MARGIN * 2 + SPACING * (count - 1); - // 根据appitem title 设置自适应宽度 auto appSnapshot = static_cast(m_windowListLayout->itemAt(0)->widget()); - auto font = appSnapshot->layout()->itemAt(0)->widget()->font(); QFontMetrics fontMetrics(font); - const int titleWidth = fontMetrics.boundingRect(appSnapshot->title()).width(); + + // 获取 appitem title 的最大宽度 + int titleWidth = fontMetrics.boundingRect(appSnapshot->title()).width(); + for (int i = 0; i < m_windowListLayout->count(); i++) { + auto otherWidget = static_cast(m_windowListLayout->itemAt(i)->widget()); + titleWidth = qMax(titleWidth, fontMetrics.boundingRect(otherWidget->title()).width()); + } + // 关闭按键的宽度和边缘间距的和,调整标题居中 const int closeBtnMargin = 2 * (SNAP_CLOSE_BTN_WIDTH + SNAP_CLOSE_BTN_MARGIN); - if (titleWidth < SNAP_WIDTH - closeBtnMargin) { + if (titleWidth < SNAP_WIDTH - closeBtnMargin) setFixedSize(titleWidth + closeBtnMargin, h); - } else { + else setFixedSize(SNAP_WIDTH, h); - } } //根据计算的数量,将相应的预览界面添加到布局并显示,其他的暂时不添加,减少界面刷新次数