Adjust prompt size hint based on content.

See #26.
Fixes #506.

Related to 06cc982ab5.
This commit is contained in:
Florian Bruhin 2015-03-09 19:34:31 +01:00
parent 9ffb30a16f
commit 8307b546b7

View File

@ -21,7 +21,8 @@
import functools
from PyQt5.QtWidgets import QHBoxLayout, QWidget, QLineEdit
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import QHBoxLayout, QWidget, QLineEdit, QSizePolicy
from qutebrowser.mainwindow.statusbar import textbase, prompter
from qutebrowser.utils import objreg, utils
@ -35,6 +36,16 @@ class PromptLineEdit(misc.MinimalLineEditMixin, QLineEdit):
def __init__(self, parent=None):
QLineEdit.__init__(self, parent)
misc.MinimalLineEditMixin.__init__(self)
self.textChanged.connect(self.updateGeometry)
def sizeHint(self):
"""Dynamically calculate the needed size."""
height = super().sizeHint().height()
text = self.text()
if not text:
text = 'x'
width = self.fontMetrics().width(text)
return QSize(width, height)
class Prompt(QWidget):
@ -58,6 +69,8 @@ class Prompt(QWidget):
self._hbox.addWidget(self.txt)
self.lineedit = PromptLineEdit()
self.lineedit.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.Fixed)
self._hbox.addWidget(self.lineedit)
prompter_obj = prompter.Prompter(win_id)