From d5de52d73c25bed636395d7e759926c36f6b5b3e Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Wed, 25 May 2016 13:50:01 +0200 Subject: [PATCH] Highlight current row Inspired by code in pireal. --- relational_gui/editor.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/relational_gui/editor.py b/relational_gui/editor.py index f6b1ee3..dc9a232 100644 --- a/relational_gui/editor.py +++ b/relational_gui/editor.py @@ -20,7 +20,11 @@ # relational operations on them. from PyQt5.QtWidgets import QPlainTextEdit +from PyQt5.QtWidgets import QTextEdit from PyQt5.QtCore import Qt +from PyQt5.QtGui import QColor +from PyQt5.QtGui import QPalette +from PyQt5.QtGui import QTextCharFormat class Editor(QPlainTextEdit): @@ -28,6 +32,30 @@ class Editor(QPlainTextEdit): def __init__(self, *args, **kwargs): super(Editor, self).__init__(*args, **kwargs) + self._cursor_moved() + self.cursorPositionChanged.connect(self._cursor_moved) + + def _cursor_moved(self): + selections = [] + + # Current line + cur_line = QTextEdit.ExtraSelection() + bgcolor = QPalette().color( + QPalette.Normal, + QPalette.Window + ).lighter() + cur_line.format.setBackground(bgcolor) + cur_line.format.setProperty( + QTextCharFormat.FullWidthSelection, + True + ) + cur_line.cursor = self.textCursor() + cur_line.cursor.clearSelection() + selections.append(cur_line) + + # Apply the selections + self.setExtraSelections(selections) + def wheelEvent(self, event): if event.modifiers() & Qt.ControlModifier: event.accept()