Make sure completion column widths never get negative

I discovered this because of #2287 but it doesn't actually change anything
there. When we don't have a third column, subtract the scrollbar width from the
second one.
This commit is contained in:
Florian Bruhin 2017-02-08 09:10:40 +01:00
parent ccb6594e07
commit c4a74c7a34

View File

@ -150,10 +150,15 @@ class CompletionView(QTreeView):
"""Resize the completion columns based on column_widths.""" """Resize the completion columns based on column_widths."""
width = self.size().width() width = self.size().width()
pixel_widths = [(width * perc // 100) for perc in self._column_widths] pixel_widths = [(width * perc // 100) for perc in self._column_widths]
if self.verticalScrollBar().isVisible(): if self.verticalScrollBar().isVisible():
pixel_widths[-1] -= self.style().pixelMetric( delta = self.style().pixelMetric(QStyle.PM_ScrollBarExtent) + 5
QStyle.PM_ScrollBarExtent) + 5 if pixel_widths[-1] > delta:
pixel_widths[-1] -= delta
else:
pixel_widths[-2] -= delta
for i, w in enumerate(pixel_widths): for i, w in enumerate(pixel_widths):
assert w >= 0, i
self.setColumnWidth(i, w) self.setColumnWidth(i, w)
def _next_idx(self, upwards): def _next_idx(self, upwards):