close-cd#I73ZTU 修复切换为华文字体后计算机视图显示问题

This commit is contained in:
wen-jiexiang 2023-06-20 11:25:33 +08:00
parent edd230e511
commit de31083031
1 changed files with 14 additions and 2 deletions

View File

@ -87,6 +87,9 @@ void ComputerItemDelegate::paintVolumeItem(QPainter *painter, const QStyleOption
int v = bg.value();
bg.setHsv(hue, 10, 127);
qDebug() << "============" << opt.font << "text:" << opt.text;
opt.palette.setColor(QPalette::Highlight, bg);
//qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, m_styleIconView);
bool isHover = (option.state & QStyle::State_MouseOver) && (option.state & ~QStyle::State_Selected);
@ -126,7 +129,9 @@ void ComputerItemDelegate::paintVolumeItem(QPainter *painter, const QStyleOption
//draw text
auto textRect = option.rect;
qDebug() << "===========" << textRect;
textRect.adjust(84, 10, -5, -25);
qDebug() << "===========last" << textRect;
textRect.translate(0, -option.fontMetrics.ascent());
auto elideText = opt.fontMetrics.elidedText(opt.text, Qt::ElideMiddle, textRect.width());
qApp->style()->drawItemText(painter, textRect, Qt::AlignLeft|Qt::AlignVCenter, option.palette, enable, elideText, QPalette::Text);
@ -156,8 +161,15 @@ void ComputerItemDelegate::paintVolumeItem(QPainter *painter, const QStyleOption
}
}
QRect spaceInfoArea = textRect.translated(0, 1.5 * option.fontMetrics.ascent());
spaceInfoArea.setHeight (option.fontMetrics.height () + 2.5 * option.fontMetrics.ascent());
QRect spaceInfoArea = textRect;
if (option.fontMetrics.ascent() <= option.font.pointSize() + 4) {
spaceInfoArea = textRect.translated(0, 2.0 * option.fontMetrics.ascent());
spaceInfoArea.setHeight (option.fontMetrics.height () + 3.0 * option.fontMetrics.ascent());
} else {
spaceInfoArea = textRect.translated(0, 1.5 * option.fontMetrics.ascent());
spaceInfoArea.setHeight (option.fontMetrics.height () + 2.5 * option.fontMetrics.ascent());
}
qApp->style()->drawItemText(painter, spaceInfoArea, Qt::AlignLeft|Qt::AlignVCenter|Qt::TextWordWrap, option.palette, enable, spaceInfo, QPalette::PlaceholderText);
if (shouldDrawProgress) {