mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Grid view: Fix bug in centering calculation
This commit is contained in:
parent
f28c60d066
commit
b1f31d3dce
@ -561,12 +561,13 @@ class GridView(QListView):
|
|||||||
def center_grid(self):
|
def center_grid(self):
|
||||||
if self.gui.library_view.alternate_views.current_view is not self:
|
if self.gui.library_view.alternate_views.current_view is not self:
|
||||||
return
|
return
|
||||||
|
layout_width = self.viewport().width() + self.padding_left
|
||||||
try:
|
try:
|
||||||
sz = self.spacing()*2 + self.delegate.item_size.width()
|
sz = self.spacing()*2 + self.delegate.item_size.width()
|
||||||
num = self.width() // sz
|
num = layout_width // sz
|
||||||
except (AttributeError, ZeroDivisionError):
|
except (AttributeError, ZeroDivisionError):
|
||||||
return
|
return
|
||||||
extra = max(0, int((self.width() - (num * sz)) / 2) - self.spacing())
|
extra = max(0, int((layout_width - (num * sz)) / 2))
|
||||||
if extra != self.padding_left:
|
if extra != self.padding_left:
|
||||||
self.padding_left = extra
|
self.padding_left = extra
|
||||||
self.setViewportMargins(self.padding_left, 0, 0, 0)
|
self.setViewportMargins(self.padding_left, 0, 0, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user