Fix cropping of message bubble cropping on linux

This commit is contained in:
Peter Stockings
2026-04-01 22:43:35 +11:00
parent f1b7a65767
commit aee78d5392

View File

@@ -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)