support files over 2 GB
This commit is contained in:
36
ScaledScrollBar.py
Normal file
36
ScaledScrollBar.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import math
|
||||
|
||||
from PyQt6.QtWidgets import QScrollBar
|
||||
import logging
|
||||
|
||||
log = logging.getLogger("scaledScrollBar")
|
||||
|
||||
|
||||
class ScaledScrollBar(QScrollBar):
|
||||
is_huge = False
|
||||
|
||||
def __init__(self):
|
||||
super(ScaledScrollBar, self).__init__()
|
||||
self.real_maximum = self.maximum()
|
||||
|
||||
def setValue(self, value: int) -> None:
|
||||
if self.is_huge:
|
||||
real_position = value / self.real_maximum
|
||||
super().setValue(self.maximum() * real_position)
|
||||
else:
|
||||
super().setValue(value)
|
||||
|
||||
def setMaximum(self, maximum: int) -> None:
|
||||
if maximum > 2 ** 31:
|
||||
new_maximum = 1000 * math.log2(maximum)
|
||||
super().setMaximum(new_maximum)
|
||||
self.real_maximum = maximum
|
||||
|
||||
if not self.is_huge:
|
||||
old_position = self.value() / self.maximum()
|
||||
self.setValue(new_maximum * old_position)
|
||||
|
||||
self.is_huge = True
|
||||
else:
|
||||
self.is_huge = False
|
||||
super().setMaximum(maximum)
|
||||
Reference in New Issue
Block a user