partially fix scrolling in files > 2 GB

This commit is contained in:
2021-10-31 13:53:17 +01:00
parent 79f9219e9a
commit bb99fb2c58
4 changed files with 27 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
import math
from PyQt6.QtWidgets import QScrollBar
from PyQt6.QtCore import pyqtSignal
import logging
log = logging.getLogger("scaledScrollBar")
@@ -9,9 +10,18 @@ log = logging.getLogger("scaledScrollBar")
class ScaledScrollBar(QScrollBar):
is_huge = False
valueChanged = pyqtSignal(str)
"""Signal emitted when the scroll bar value changes.
**Note**: The value is a string and must be parsed into an int.
QT's signal api only supports 32bit integers. Ints larger
than 2**32-1 will overflow. Probably because there is some C/C++
code involved. We work around this by converting the python int
into a string."""
def __init__(self):
super(ScaledScrollBar, self).__init__()
self.real_maximum = self.maximum()
super().valueChanged.connect(self._valueChanged)
def setValue(self, value: int) -> None:
if self.is_huge:
@@ -34,3 +44,11 @@ class ScaledScrollBar(QScrollBar):
else:
self.is_huge = False
super().setMaximum(maximum)
def _valueChanged(self, value: int):
if self.is_huge:
real_value = (value / self.maximum()) * self.real_maximum
# print("scaled value changed: %d -> %d (%f)" % (value, real_value, value / self.maximum()))
self.valueChanged.emit(str(int(real_value)))
else:
self.valueChanged.emit(str(int(value)))