From 1d6811bf7e2ff87fcc595e9245454d712a2c7214 Mon Sep 17 00:00:00 2001 From: jolavillette Date: Sun, 16 Aug 2026 12:52:30 +0200 Subject: [PATCH] gui(chat): stop shrinking the room list when marking items bold The bold font used for the unread counters was derived from the item itself, with QTreeWidgetItem::font(). That call returns a default constructed font when the item carries no Qt::FontRole yet, i.e. the application font, not the font of the tree. And RSElidedItemDelegate paints an item with the model font as is, without merging it into the font of the view, so every room and every branch ended up drawn at the application font size instead of the size configured in the settings, which FontSizeHandler puts on the tree widget. The whole room list looked one point smaller than the rest of the GUI. Derive the bold font from the tree widget instead, and drop the Qt::FontRole altogether when an item is not bold, so that unread-free items keep following the settings font size when it changes. Co-Authored-By: Claude Opus 5 (1M context) --- retroshare-gui/src/gui/ChatLobbyWidget.cpp | 31 +++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.cpp b/retroshare-gui/src/gui/ChatLobbyWidget.cpp index 5ad85df08..d7f5879f6 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.cpp +++ b/retroshare-gui/src/gui/ChatLobbyWidget.cpp @@ -330,6 +330,29 @@ void ChatLobbyWidget::updateNotify(ChatLobbyId id, unsigned int count) * when it has unread messages, so that a collapsed branch still tells that something * is waiting inside. */ +/*! + * \brief Put an item of the room tree in bold, or back to normal. + * + * The tree itself carries the font size taken from the settings (see FontSizeHandler), + * but QTreeWidgetItem::font() returns a default constructed font when the item has no + * Qt::FontRole yet, and RSElidedItemDelegate paints the item with the model font as is, + * without merging it into the font of the view. Deriving the bold font from the item + * would therefore shrink the whole list down to the application font. So derive it from + * the tree, and remove the role altogether when the item is not bold, so that it keeps + * following the font size of the settings. + */ +static void setItemBold(QTreeWidget *treeWidget, QTreeWidgetItem *item, bool bold) +{ + if(bold) + { + QFont font = treeWidget->font(); + font.setBold(true); + item->setFont(COLUMN_NAME, font); + } + else + item->setData(COLUMN_NAME, Qt::FontRole, QVariant()); +} + void ChatLobbyWidget::updateUnreadCounters() { QTreeWidgetItem *branches[4] = { privateSubLobbyItem, publicSubLobbyItem, privateLobbyItem, publicLobbyItem }; @@ -366,9 +389,7 @@ void ChatLobbyWidget::updateUnreadCounters() item->setText(COLUMN_NAME, unread ? QString("%1 [%2]").arg(name).arg(unread) : name); - QFont font = item->font(COLUMN_NAME); - font.setBold(unread > 0); - item->setFont(COLUMN_NAME, font); + setItemBold(ui.lobbyTreeWidget, item, unread > 0); } QString label = branch->data(COLUMN_NAME, ROLE_BASE_NAME).toString(); @@ -382,9 +403,7 @@ void ChatLobbyWidget::updateUnreadCounters() branch->setText(COLUMN_NAME, label); branch->setToolTip(COLUMN_NAME, branch_unread ? tr("%n unread message(s)", "", branch_unread) : QString()); - QFont font = branch->font(COLUMN_NAME); - font.setBold(branch_unread > 0); - branch->setFont(COLUMN_NAME, font); + setItemBold(ui.lobbyTreeWidget, branch, branch_unread > 0); } }