From aee78d53928600723ae55251bed7f368b26b3f4f Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Wed, 1 Apr 2026 22:43:35 +1100 Subject: [PATCH] Fix cropping of message bubble cropping on linux --- desktop-client/chat_widgets.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/desktop-client/chat_widgets.py b/desktop-client/chat_widgets.py index 48b97af..29a50b5 100644 --- a/desktop-client/chat_widgets.py +++ b/desktop-client/chat_widgets.py @@ -1,6 +1,6 @@ from PyQt6.QtWidgets import ( QWidget, QVBoxLayout, QHBoxLayout, QLabel, QFrame, - QMainWindow + QMainWindow, QSizePolicy ) from PyQt6.QtCore import Qt, pyqtSignal @@ -14,6 +14,13 @@ class ChatBubble(QWidget): # Container for the actual bubble self.bubble = QFrame() self.bubble.setObjectName("bubble") + # Preferred/Preferred: bubble sizes to its content but doesn't + # expand to fill all available horizontal space (fixes Linux layout). + self.bubble.setSizePolicy( + QSizePolicy.Policy.Preferred, + QSizePolicy.Policy.Preferred, + ) + self.bubble.setMaximumWidth(420) bg_color = "#0084FF" if is_self else "#2a2a2e" text_color = "#FFFFFF" @@ -35,9 +42,17 @@ class ChatBubble(QWidget): author_lbl.setStyleSheet(f"color: {author_color}; font-weight: bold; font-size: 11px; background: transparent;") bubble_layout.addWidget(author_lbl) - # Text + # Text — on Linux, word-wrapping QLabels inside HBoxLayouts can + # overflow their parent's painted area. Setting Preferred + minimum + # width of 0 lets the label wrap within whatever space the bubble + # actually receives rather than expanding the bubble outward. self.text_lbl = QLabel(text) self.text_lbl.setWordWrap(True) + self.text_lbl.setMinimumWidth(0) + self.text_lbl.setSizePolicy( + QSizePolicy.Policy.Preferred, + QSizePolicy.Policy.Preferred, + ) self.text_lbl.setStyleSheet(f"color: {text_color}; font-size: 13px; border: none; background: transparent;") self.text_lbl.setOpenExternalLinks(False) self.text_lbl.linkActivated.connect(on_link_clicked)