修复文本类型下面总是多一行的问题,同时取消限制item高度加1

This commit is contained in:
2026-07-31 09:48:26 +08:00
parent 775eb4daaa
commit d775427307
2 changed files with 18 additions and 1 deletions
+17
View File
@@ -557,6 +557,23 @@ QImage ItemUtils::txtToImage(const QString &txt, const QFont &font, const QColor
QFontMetrics fm(font);
int width = fm.horizontalAdvance(txt);
int height = fm.height();
// 优先使用字体名中后缀标识的字体高度
QString fontname = font.family();
QString numStr = "";
for(int i = fontname.length() - 1; i >= 0; --i) {
if(fontname[i].isDigit()) {
numStr.prepend(fontname[i]);
} else {
break;
}
}
if(!numStr.isEmpty()) {
height = numStr.toInt();
if(height < 5 || height > 32)
height = fm.height();
}
if (width <= 0 || height <= 0) {
return QImage();
}