Some issues with QTextEdit (PySide2)
-
Hi,
-
when setting self.setAlignment(QtCore.Qt.AlignRight) on a QTextEdit instance, then setting <an_extra_selection>.format.setProperty(QtGui.QTextFormat.FullWidthSelection, True) does not put that extra selection over whole line (like when you do current-line highlighting).
-
following movements of cursor by setting self.cursorPositionChanged.connect(self.<method_for_line_highlighting>) does not suffice, since doing select-all action (by Ctrl-A) moves the text cursor (putting it to the text end) without triggering the signaling. It is necessary to follow the selectionChanged signaling too.
I'm using PySide2 under Ubuntu 16.04, Python3:
import PySide2
PySide2.__ version_info __
(2, 0, 0, 'alpha', 0) -
-
Hi and welcome to devnet,
You should provide a complete code example otherwise it's pretty much impossible to reproduce the behaviour you're describing.
-
Hi, I encountered it when developing a simple app. I was able to deal with it somehow, thus this is meant as a notice about these issues for Qt people.
The missing signaling on select-all event can be seen by commenting out self.highlight_current_line() at (one of) def selection_changed(self): there.
The issue with line highlighting of right-aligned lines can be seen by adding self.setAlignment(QtCore.Qt.AlignRight) at one of the QTextEdit-based classes, like at class CmdTextEdit(QTextEdit): e.g. just before self.setUndoRedoEnabled(True) by the end of its __init__:
self.setAlignment(QtCore.Qt.AlignRight)
self.document().setModified(False)
self.setUndoRedoEnabled(True)with the self.document().setModified(False) being put there to convince Qt that this setting is still within initialization.
BTW I've seen at the Qt example that line numbers are thought to be drawn by painters, though the painter did not want to work for me (complaining about something, may be about being not active, not sure now). And since I did not know how to convert that example onto partially-seen lines anyway, I did it a different way.