From 61e647081ce79675def9b37f880effed43bab803 Mon Sep 17 00:00:00 2001 From: jolavillette Date: Sun, 16 Aug 2026 13:06:39 +0200 Subject: [PATCH] gui: let RSElidedItemDelegate inherit the view font from the model font MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The delegate took the Qt::FontRole of the model and assigned it to the style option as is, replacing the font of the view instead of merging into it. A font stored in a model usually only carries the one attribute the caller wanted to change — most of the time bold — and expects family and size to keep coming from the view. Assigning it whole dropped those items back to the application font, ignoring the font size configured in the settings, which FontSizeHandler puts on the view. That is easy to trigger: QTreeWidgetItem::font() returns a default constructed font when the item has no Qt::FontRole yet, so the familiar "read the font, set it bold, write it back" turned the whole list into the application font. On a remote X display where the desktop font is 9pt and the RetroShare font size is 11pt, the list visibly shrank. Merge with QFont::resolve() instead, which keeps only the attributes the model really set and takes the rest from the view — the same merge QStyledItemDelegate::initStyleOption() performs. Same change in the tooltip path of editorEvent(), which recomputes the elision with that font. sizeHint() was already using the merged font from initStyleOption(), so rows were being measured with one font and painted with another. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/gui/common/RSElidedItemDelegate.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp b/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp index 5303f2b10..a85f4fd62 100644 --- a/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp +++ b/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp @@ -137,9 +137,13 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & td.setHtml(ownOption.text); ownOption.text = td.toPlainText(); } - // Get Font as option.font is not accurate + // Get Font as option.font is not accurate. Merge it into the font of the view instead + // of replacing it: a font stored in the model usually only sets a couple of attributes + // (bold, italic) and expects the rest (family, size) to be inherited from the view. + // QFont::resolve() keeps exactly what the model really set and takes the rest from the + // view, which is what QStyledItemDelegate::initStyleOption() does as well. if (index.data(Qt::FontRole).type() == QVariant::Font) { - QFont font = index.data(Qt::FontRole).value(); + QFont font = index.data(Qt::FontRole).value().resolve(ownOption.font); ownOption.font = font; ownOption.fontMetrics = QFontMetrics(font); #ifdef DEBUG_EID_PAINT @@ -421,9 +425,9 @@ bool RSElidedItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, td.setHtml(ownOption.text); ownOption.text = td.toPlainText(); } - //Get Font as option.font is not accurate + //Get Font as option.font is not accurate, merged into the one of the view (see paint()) if (index.data(Qt::FontRole).type() == QVariant::Font) { - QFont font = index.data(Qt::FontRole).value(); + QFont font = index.data(Qt::FontRole).value().resolve(ownOption.font); ownOption.font = font; ownOption.fontMetrics = QFontMetrics(font); }