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); - } } //根据计算的数量,将相应的预览界面添加到布局并显示,其他的暂时不添加,减少界面刷新次数