give focus on wheel scrolling

This commit is contained in:
2021-10-25 16:23:03 +02:00
parent 603b748180
commit 1fce6c02ff
2 changed files with 6 additions and 5 deletions

View File

@@ -64,6 +64,7 @@ class InnerBigText(QWidget):
self.model = model self.model = model
self.parent = parent self.parent = parent
self.setFocusPolicy(Qt.FocusPolicy.StrongFocus) self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
self.setFocusPolicy(Qt.FocusPolicy.WheelFocus)
self.font = QFont("monospace", 12) self.font = QFont("monospace", 12)
self.update_font_metrics(QPainter(self)) self.update_font_metrics(QPainter(self))
@@ -84,13 +85,13 @@ class InnerBigText(QWidget):
def keyPressEvent(self, e: QKeyEvent) -> None: def keyPressEvent(self, e: QKeyEvent) -> None:
lines_to_scroll = math.floor(self.lines_shown()) -1 lines_to_scroll = math.floor(self.lines_shown()) -1
if e.key() == Qt.Key.Key_PageUp: 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) 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: if e.key() == 16777235:
self.scroll_by_lines(3)
if e.key() == 16777237:
self.scroll_by_lines(-3) self.scroll_by_lines(-3)
if e.key() == 16777237:
self.scroll_by_lines(3)
def wheelEvent(self, event: QWheelEvent): def wheelEvent(self, event: QWheelEvent):
direction = 1 if event.angleDelta().y() < 0 else -1 direction = 1 if event.angleDelta().y() < 0 else -1

View File

@@ -13,7 +13,7 @@ class LogFileModel:
self._file = file self._file = file
def data(self, byte_offset, scroll_lines, lines) -> List[Line]: 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_before_offset: List[Line] = []
lines_after_offset: List[Line] = [] lines_after_offset: List[Line] = []
result: List[Line] = [] result: List[Line] = []