fix: 关闭窗口特效模式,已打开的的应用在任务栏上tooltip窗口没有根据文案长度自适应

修改自定义类PreviewContainer,tooltop窗口宽度根据应用名称进行自适应调整

Log: 关闭窗口特效模式,已打开的的应用在任务栏上tooltip窗口没有根据文案长度自适应
Bug: https://pms.uniontech.com/zentao/bug-view-59714.html
Change-Id: Iaaed00e26cd6f4f0e9e5ea68b24443ab7c1b3d8c
This commit is contained in:
yangyuyin 2021-01-06 17:52:20 +08:00 committed by niecheng
parent d3b230a569
commit 4c85face8b

View File

@ -140,7 +140,18 @@ void PreviewContainer::adjustSize()
if (!composite)
{
const int h = SNAP_HEIGHT_WITHOUT_COMPOSITE * count + MARGIN * 2 + SPACING * (count - 1);
setFixedSize(SNAP_WIDTH, h);
//根据appitem title 设置自适应宽度
auto appSnapshot = static_cast<AppSnapshot*>(this->layout()->itemAt(0)->widget());
auto font = appSnapshot->layout()->itemAt(0)->widget()->font();
QFontMetrics fontMetrics(font);
const int fontSize = fontMetrics.boundingRect(appSnapshot->title()).width();
//预留字体到边缘的间距,边缘距离10px,关闭按钮24px
if (fontSize < SNAP_WIDTH - 44)
setFixedSize(fontSize + 44, h);
else
setFixedSize(SNAP_WIDTH, h);
return;
}