Repository: qutebrowser/qutebrowser

Issue:
Wrap messages
Messages aren't wrapped when their text is too long:

![image](https://user-images.githubusercontent.com/625793/48582097-e763ba80-e923-11e8-826a-6f81d5887d67.png)



Discussion:
Setting `self.setWordWrap(True)` in `Message.__init__` works, but has another problem - the height of the message may be too large:

![screenshot from 2018-11-19 19-50-12](https://user-images.githubusercontent.com/25191436/48708826-37999000-ec36-11e8-9ab3-a38bb97d397a.png)

I don't follow - that seems fine from the screenshot?
This screenshot may be more apparent (that the top and bottom padding is too large):

![image](https://user-images.githubusercontent.com/25191436/48709023-d4f4c400-ec36-11e8-8f55-47514f6b624d.png)




Resolving patch:
diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py
--- a/qutebrowser/mainwindow/mainwindow.py
+++ b/qutebrowser/mainwindow/mainwindow.py
@@ -304,12 +304,17 @@ def _update_overlay_geometry(self, widget, centered, padding):
         if not widget.isVisible():
             return
 
-        size_hint = widget.sizeHint()
         if widget.sizePolicy().horizontalPolicy() == QSizePolicy.Expanding:
             width = self.width() - 2 * padding
+            if widget.hasHeightForWidth():
+                height = widget.heightForWidth(width)
+            else:
+                height = widget.sizeHint().height()
             left = padding
         else:
+            size_hint = widget.sizeHint()
             width = min(size_hint.width(), self.width() - 2 * padding)
+            height = size_hint.height()
             left = (self.width() - width) // 2 if centered else 0
 
         height_padding = 20
@@ -321,7 +326,7 @@ def _update_overlay_geometry(self, widget, centered, padding):
             else:
                 status_height = 0
                 bottom = self.height()
-            top = self.height() - status_height - size_hint.height()
+            top = self.height() - status_height - height
             top = qtutils.check_overflow(top, 'int', fatal=False)
             topleft = QPoint(left, max(height_padding, top))
             bottomright = QPoint(left + width, bottom)
@@ -333,7 +338,7 @@ def _update_overlay_geometry(self, widget, centered, padding):
                 status_height = 0
                 top = 0
             topleft = QPoint(left, top)
-            bottom = status_height + size_hint.height()
+            bottom = status_height + height
             bottom = qtutils.check_overflow(bottom, 'int', fatal=False)
             bottomright = QPoint(left + width,
                                  min(self.height() - height_padding, bottom))
diff --git a/qutebrowser/mainwindow/messageview.py b/qutebrowser/mainwindow/messageview.py
--- a/qutebrowser/mainwindow/messageview.py
+++ b/qutebrowser/mainwindow/messageview.py
@@ -21,7 +21,7 @@
 
 import typing
 
-from PyQt5.QtCore import pyqtSlot, pyqtSignal, QTimer, Qt, QSize
+from PyQt5.QtCore import pyqtSlot, pyqtSignal, QTimer, Qt
 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QSizePolicy
 
 from qutebrowser.config import config, stylesheet
@@ -36,6 +36,7 @@ def __init__(self, level, text, replace, parent=None):
         super().__init__(text, parent)
         self.replace = replace
         self.setAttribute(Qt.WA_StyledBackground, True)
+        self.setWordWrap(True)
         qss = """
             padding-top: 2px;
             padding-bottom: 2px;
@@ -64,8 +65,6 @@ def __init__(self, level, text, replace, parent=None):
             """
         else:  # pragma: no cover
             raise ValueError("Invalid level {!r}".format(level))
-        # We don't bother with set_register_stylesheet here as it's short-lived
-        # anyways.
         stylesheet.set_register(self, qss, update=False)
 
 
@@ -89,12 +88,6 @@ def __init__(self, parent=None):
 
         self._last_text = None
 
-    def sizeHint(self):
-        """Get the proposed height for the view."""
-        height = sum(label.sizeHint().height() for label in self._messages)
-        # The width isn't really relevant as we're expanding anyways.
-        return QSize(-1, height)
-
     @config.change_filter('messages.timeout')
     def _set_clear_timer_interval(self):
         """Configure self._clear_timer according to the config."""


Test patch: