I know how to select (again not too hard) but need to know how to change the color of a single line from a QTextEdit?
Example:
Line 1
Line 2
Line 3 highlighted
Line 4
Line 5 highlighted
I know how to select (again not too hard) but need to know how to change the color of a single line from a QTextEdit?
Example:
Line 1
Line 2
Line 3 highlighted
Line 4
Line 5 highlighted
To select, use QTextCursor like this (you can move the cursor before selecting with setPosition ( QTextCursor: KeepAnchor)):
Code:QTextCursor textEdit = cursor -> TextCursor (); cursor. setPosition (n QTextCursor: KeepAnchor); textEdit -> setTextCursor (cursor);
The QTextCursor class offers an API to access and modify QTextDocuments, TextEdit does indeed support the desired display of text/color/background combination and even that can be further edited.
Code:// Style Sheet textEdit->setStyleSheet("color: black; background-color: white; selection-color: white; selection-background-color: black;");
Code:QTextCursor textEdit = cursor -> TextCursor () / / It gets a QTextCursor the text box cursor. setPosition (n QTextCursor: KeepAnchor) / / The location n is the position recovered by indexOf ( "test") on textEdit-> toPlainText () textEdit -> setTextCursor (cursor) / / Used in this case to ensure that the selection is visible to the user
Bookmarks