Adjust prompt size hint based on content.
See #26.
Fixes #506.
Related to 06cc982ab5
.
This commit is contained in:
parent
9ffb30a16f
commit
8307b546b7
@ -21,7 +21,8 @@
|
|||||||
|
|
||||||
import functools
|
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.mainwindow.statusbar import textbase, prompter
|
||||||
from qutebrowser.utils import objreg, utils
|
from qutebrowser.utils import objreg, utils
|
||||||
@ -35,6 +36,16 @@ class PromptLineEdit(misc.MinimalLineEditMixin, QLineEdit):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QLineEdit.__init__(self, parent)
|
QLineEdit.__init__(self, parent)
|
||||||
misc.MinimalLineEditMixin.__init__(self)
|
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):
|
class Prompt(QWidget):
|
||||||
@ -58,6 +69,8 @@ class Prompt(QWidget):
|
|||||||
self._hbox.addWidget(self.txt)
|
self._hbox.addWidget(self.txt)
|
||||||
|
|
||||||
self.lineedit = PromptLineEdit()
|
self.lineedit = PromptLineEdit()
|
||||||
|
self.lineedit.setSizePolicy(QSizePolicy.MinimumExpanding,
|
||||||
|
QSizePolicy.Fixed)
|
||||||
self._hbox.addWidget(self.lineedit)
|
self._hbox.addWidget(self.lineedit)
|
||||||
|
|
||||||
prompter_obj = prompter.Prompter(win_id)
|
prompter_obj = prompter.Prompter(win_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user