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.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