From 1fce6c02ff86feacfb0710b9a18360982be8eaaa Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Mon, 25 Oct 2021 16:23:03 +0200 Subject: [PATCH] give focus on wheel scrolling --- bigtext.py | 9 +++++---- logFileModel.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bigtext.py b/bigtext.py index 679a73d..78d2940 100644 --- a/bigtext.py +++ b/bigtext.py @@ -64,6 +64,7 @@ class InnerBigText(QWidget): self.model = model self.parent = parent self.setFocusPolicy(Qt.FocusPolicy.StrongFocus) + self.setFocusPolicy(Qt.FocusPolicy.WheelFocus) self.font = QFont("monospace", 12) self.update_font_metrics(QPainter(self)) @@ -84,13 +85,13 @@ class InnerBigText(QWidget): def keyPressEvent(self, e: QKeyEvent) -> None: lines_to_scroll = math.floor(self.lines_shown()) -1 if e.key() == Qt.Key.Key_PageUp: - self.scroll_by_lines(lines_to_scroll) - if e.key() == Qt.Key.Key_PageDown: self.scroll_by_lines(-lines_to_scroll) + if e.key() == Qt.Key.Key_PageDown: + self.scroll_by_lines(lines_to_scroll) if e.key() == 16777235: - self.scroll_by_lines(3) - if e.key() == 16777237: self.scroll_by_lines(-3) + if e.key() == 16777237: + self.scroll_by_lines(3) def wheelEvent(self, event: QWheelEvent): direction = 1 if event.angleDelta().y() < 0 else -1 diff --git a/logFileModel.py b/logFileModel.py index b5c3dfb..fe7d351 100644 --- a/logFileModel.py +++ b/logFileModel.py @@ -13,7 +13,7 @@ class LogFileModel: self._file = file def data(self, byte_offset, scroll_lines, lines) -> List[Line]: - print("data(%s, %s, %s)" % (byte_offset, scroll_lines, lines)) + #print("data(%s, %s, %s)" % (byte_offset, scroll_lines, lines)) lines_before_offset: List[Line] = [] lines_after_offset: List[Line] = [] result: List[Line] = []