Fix ElidedLabel when Font size is not defined.

This commit is contained in:
Phenom 2022-03-28 19:04:02 +02:00
parent 28017566f1
commit 3540b1ae38
2 changed files with 5 additions and 7 deletions

View File

@ -128,6 +128,7 @@ bool ElidedLabel::paintElidedLine( QPainter* painter, QString plainText
if (painter) if (painter)
{ {
useFont.setPointSize(useFont.pointSize()); //Modify it to be copied in painter. Else painter keep defaut font size.
painter->save(); painter->save();
painter->setFont(useFont); painter->setFont(useFont);
} }

View File

@ -143,8 +143,7 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
ownOption.font = font; ownOption.font = font;
ownOption.fontMetrics = QFontMetrics(font); ownOption.fontMetrics = QFontMetrics(font);
#ifdef DEBUG_EID_PAINT #ifdef DEBUG_EID_PAINT
QFontInfo info(font); RsDbg(" RSEID: Found font in model:", font.family().toStdString(), " size:", font.pointSize());
RsDbg(" RSEID: Found font in model:", info.family().toStdString());
#endif #endif
} }
// Get Text color from model if one exists // Get Text color from model if one exists
@ -383,14 +382,12 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
ownOption.text = ownOption.text.prepend("__"); ownOption.text = ownOption.text.prepend("__");
#endif #endif
QTextLayout textLayout(ownOption.text, painter->font()); QTextOption::WrapMode wm = (ownOption.features & QStyleOptionViewItem::WrapText) ? QTextOption::WordWrap : QTextOption::NoWrap;
QTextOption to = textLayout.textOption();
to.setWrapMode((ownOption.features & QStyleOptionViewItem::WrapText) ? QTextOption::WordWrap : QTextOption::NoWrap);
const int textHMargin = ownStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, widget) + 1; const int textHMargin = ownStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, widget) + 1;
const int textVMargin = ownStyle->pixelMetric(QStyle::PM_FocusFrameVMargin, nullptr, widget) + 1; const int textVMargin = ownStyle->pixelMetric(QStyle::PM_FocusFrameVMargin, nullptr, widget) + 1;
textRect = textRect.adjusted(textHMargin, textVMargin, -textHMargin, -textVMargin); // remove width padding textRect = textRect.adjusted(textHMargin, textVMargin, -textHMargin, -textVMargin); // remove width padding
ElidedLabel::paintElidedLine(painter,ownOption.text,textRect,ownOption.font,ownOption.displayAlignment,to.wrapMode(),mPaintRoundedRect); ElidedLabel::paintElidedLine(painter,ownOption.text,textRect,ownOption.font,ownOption.displayAlignment,wm,mPaintRoundedRect);
} }
painter->restore(); painter->restore();
#ifdef DEBUG_EID_PAINT #ifdef DEBUG_EID_PAINT