Fix qtconsole input prompt accounting

- Ensure prompt text is flushed after showing
- Ensure prompt position is adjusted when reading input
- Keep pending text to insert only when inserting at end

This fixes `ipdb>` input prompts when debugging a file
in qtconsole.
Merge pull request #6245 from pankajp/fix-qtconsole-prompt-accounting

Fix qtconsole input prompt accounting