summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-06-22 13:57:28 +0200
committerFlorian Bruhin <me@the-compiler.org>2020-06-22 20:08:30 +0200
commit73d098d5cb60d2f0770a4b19f4bd40b4ea500bb7 (patch)
tree181d7915c445c40c47b7cdbae0812f6ceb5d1ea5
parentf5f3bf63b58d5a2a73a777b199b9dbc0b360fb66 (diff)
downloadqutebrowser-73d098d5cb60d2f0770a4b19f4bd40b4ea500bb7.tar.gz
qutebrowser-73d098d5cb60d2f0770a4b19f4bd40b4ea500bb7.zip
miscwidget: Base WrapperLayout on QVBoxLayout
This way we don't have to care about things like sizeHint manually.
-rw-r--r--qutebrowser/misc/miscwidgets.py31
1 files changed, 10 insertions, 21 deletions
diff --git a/qutebrowser/misc/miscwidgets.py b/qutebrowser/misc/miscwidgets.py
index d5d4d6300..8dca26b53 100644
--- a/qutebrowser/misc/miscwidgets.py
+++ b/qutebrowser/misc/miscwidgets.py
@@ -23,8 +23,8 @@ import typing
from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QSize, QTimer
from PyQt5.QtWidgets import (QLineEdit, QWidget, QHBoxLayout, QLabel,
- QStyleOption, QStyle, QLayout, QApplication,
- QSplitter)
+ QStyleOption, QStyle, QLayout, QVBoxLayout,
+ QApplication, QSplitter)
from PyQt5.QtGui import QValidator, QPainter, QResizeEvent
from qutebrowser.config import config, configfiles
@@ -229,7 +229,7 @@ class _FoldArrow(QWidget):
return QSize(8, 8)
-class WrapperLayout(QLayout):
+class WrapperLayout(QVBoxLayout):
"""A Qt layout which simply wraps a single widget.
@@ -239,27 +239,13 @@ class WrapperLayout(QLayout):
def __init__(self, parent=None):
super().__init__(parent)
+ self.setContentsMargins(0, 0, 0, 0)
self._widget = None # type: typing.Optional[QWidget]
self._container = None # type: typing.Optional[QWidget]
- def addItem(self, _widget):
- raise utils.Unreachable
-
- def sizeHint(self):
- if self._widget is None:
- return QSize()
- return self._widget.sizeHint()
-
- def itemAt(self, _index):
- return None
-
- def takeAt(self, _index):
- raise utils.Unreachable
-
- def setGeometry(self, rect):
- if self._widget is None:
- return
- self._widget.setGeometry(rect)
+ def addWidget(self, widget):
+ super().addWidget(widget)
+ assert self.count() == 1
def wrap(self, container, widget):
"""Wrap the given widget in the given container."""
@@ -267,6 +253,7 @@ class WrapperLayout(QLayout):
self._widget = widget
container.setFocusProxy(widget)
widget.setParent(container)
+ self.addWidget(widget)
def unwrap(self):
"""Remove the widget from this layout.
@@ -277,9 +264,11 @@ class WrapperLayout(QLayout):
return
assert self._container is not None
+ self.takeAt(0)
self._widget.setParent(None) # type: ignore[call-overload]
self._widget = None
self._container.setFocusProxy(None)
+ assert self.count() == 0
class PseudoLayout(QLayout):