Make ncols calculation a little more robust

This commit is contained in:
Kovid Goyal 2017-09-19 17:27:51 +05:30
parent 9537bfeff2
commit d0cf78b717
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -987,9 +987,9 @@ class GridView(QListView):
def number_of_columns(self): def number_of_columns(self):
# Number of columns currently visible in the grid # Number of columns currently visible in the grid
if self._ncols is None: if self._ncols is None:
step = self.spacing() step = max(10, self.spacing())
for y in range(step, 300, step): for y in range(step, 500, step):
for x in range(step, 300, step): for x in range(step, 500, step):
i = self.indexAt(QPoint(x, y)) i = self.indexAt(QPoint(x, y))
if i.isValid(): if i.isValid():
for x in range(self.viewport().width() - step, self.viewport().width() - 300, -step): for x in range(self.viewport().width() - step, self.viewport().width() - 300, -step):
@ -997,7 +997,6 @@ class GridView(QListView):
if j.isValid(): if j.isValid():
self._ncols = j.row() - i.row() + 1 self._ncols = j.row() - i.row() + 1
return self._ncols return self._ncols
break
return self._ncols return self._ncols
def keyPressEvent(self, ev): def keyPressEvent(self, ev):