Select whole line on click in TextArea
-
When the user sets the cursor somewhere in the text, I'd like to have TextArea select the whole line. TextArea doesn't provide an easy way to figure out in which line the cursor is, though. There's only a cursorPosition property, which is a single integer, and since lines can have different lengths, it can't be used to figure out the cursor's current line. How can I get the line number the cursor is in?
-
There are methods to set the selection: select(), moveCursorSelection(), etc.
Try to connect the clicked signal to a slot that places the cursor at the start of the current line, and then calls moveCursorSelection to move the cursor at the end of the current line and select everything.
-
@tyrathect
You should take a look at QTextCursor Doc
richtext cursor -
@tyrathect You don't. You access the QTextDocument of the TextArea, and create a cursor to manipulate it, something similar to this:
var textDocument = myTextArea.textDocument QTextCursor cursor(textDocument); //have fun with your cursor