From 3540b1ae38885ac2391ef021962b9d8b849fd68f Mon Sep 17 00:00:00 2001 From: Phenom Date: Mon, 28 Mar 2022 19:04:02 +0200 Subject: [PATCH] Fix ElidedLabel when Font size is not defined. --- retroshare-gui/src/gui/common/ElidedLabel.cpp | 3 ++- retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/retroshare-gui/src/gui/common/ElidedLabel.cpp b/retroshare-gui/src/gui/common/ElidedLabel.cpp index e44927df3..31351b08d 100644 --- a/retroshare-gui/src/gui/common/ElidedLabel.cpp +++ b/retroshare-gui/src/gui/common/ElidedLabel.cpp @@ -128,6 +128,7 @@ bool ElidedLabel::paintElidedLine( QPainter* painter, QString plainText if (painter) { + useFont.setPointSize(useFont.pointSize()); //Modify it to be copied in painter. Else painter keep defaut font size. painter->save(); painter->setFont(useFont); } @@ -152,7 +153,7 @@ bool ElidedLabel::paintElidedLine( QPainter* painter, QString plainText QTextLine lineEnd = textLayout.createLine(); if (!lineEnd.isValid() && (wordWrap #if QT_VERSION < QT_VERSION_CHECK(5,11,0) - || (fontMetrics.width(lastLine) < cr.width()) )) + || (fontMetrics.width(lastLine) < cr.width()) )) #else || (fontMetrics.horizontalAdvance(lastLine) < cr.width()) )) #endif diff --git a/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp b/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp index 80f37befc..f90591d8c 100644 --- a/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp +++ b/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp @@ -143,8 +143,7 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & ownOption.font = font; ownOption.fontMetrics = QFontMetrics(font); #ifdef DEBUG_EID_PAINT - QFontInfo info(font); - RsDbg(" RSEID: Found font in model:", info.family().toStdString()); + RsDbg(" RSEID: Found font in model:", font.family().toStdString(), " size:", font.pointSize()); #endif } // Get Text color from model if one exists @@ -383,14 +382,12 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & ownOption.text = ownOption.text.prepend("__"); #endif - QTextLayout textLayout(ownOption.text, painter->font()); - QTextOption to = textLayout.textOption(); - to.setWrapMode((ownOption.features & QStyleOptionViewItem::WrapText) ? QTextOption::WordWrap : QTextOption::NoWrap); + QTextOption::WrapMode wm = (ownOption.features & QStyleOptionViewItem::WrapText) ? QTextOption::WordWrap : QTextOption::NoWrap; const int textHMargin = ownStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, widget) + 1; const int textVMargin = ownStyle->pixelMetric(QStyle::PM_FocusFrameVMargin, nullptr, widget) + 1; 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(); #ifdef DEBUG_EID_PAINT