Improve handling of cursor_start and cursor_end for QtConsole completions.

This partially addresses #6690.

Also, a few trailing whitespaces that my editor removed...
The difference is that I am setting the cursor *in the console*, not just operating on a local cursor.