Improve handling of cursor_start and cursor_end for QtConsole completions.

This partially addresses #6690.

Also, a few trailing whitespaces that my editor removed...
What's the distinction between the local cursor and the control cursor?

@ccordoba12 is more familiar than me with Qt, he may be able to help review this.