1

Ive been looking though the QsciScintilla API, and I want to know how to set a line in a text editor to read -only. I know it provides a setReadOnly function. But this sets the whole text editor to read-only.

Any suggestions on how to set a line to read-only?

Im using PQT4 Python 3x

Pro-grammer
  • 862
  • 3
  • 15
  • 41
  • I believe QsciScintilla gives you the option of intercepting user actions, no? You might be able to use this to veto an edit by the user: so if the user presses delete, bs, or a key, your function checks if it is on that line that is read-only, if yes then your code rejects that user action event. – Oliver Mar 16 '14 at 17:36
  • @Schollii. But what if the user deletes or over-writes a larger chunk of text that happens to contain the "read-only" line? How will you prevent that? – ekhumoro Mar 16 '14 at 17:39
  • @ekhumoro Same strategy: intercept delete on a selection, see if any of the selected lines is one of the read-only lines, if so, reject. Mind you, Pro-grammer might have other requirements not mentioned like show warning with ok/cancel, etc. – Oliver Mar 16 '14 at 19:22
  • @Schollii. What should happen if you delete or insert lines above the read-only ones? I don't think tracking user actions alone is enough. The read-only lines would need to have a marker attached to them (there is an existing API for doing this) so that their positions could be tracked. But even if this was done, there is a lot of other built-in Scintilla functionality that would need to be disabled (or worked-around) in order to avoid clobbering things inadvertently. Your stategy would be a _lot_ easier to implement with a QTextEdit than with QScintilla. – ekhumoro Mar 16 '14 at 20:29

1 Answers1

0

You can't really do this. There is a low-level feature in the underlying Scintilla control that can prevent the caret moving into an area of text - but it cannot prevent deletion of a broader area of text that contains a "read-only" part. But even if this was sufficient for your purposes, this feature can only be applied to ranges of styled text, not specific lines.

If you just want to associate some read-only text with a specific line, you could use an annotation.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336