I have a lineEdit (part of QComboBox). The width of the box isn't enough for the entire string I put in it, so naturally it's truncated, but scrollable.

I wish to highlight a portion of the text. I can do this easily enough with setSelection(). However, the selected text is always at the end so you can't see any of the text after the selection. I would prefer if at least a few characters were visible after the selection. I've tried moving the cursor, but setSelection just moves it back again.

So, for example, with this text: abcdefghijklmnopqrstuvwxyz, you maybe just see 'abcdefghijklmnopqrs'. I select 'uvw', and now I see 'efghijklmnopqrst[uvw]', but I would prefer to see 'hijklmnopqrst[uvw]xyz', so the selected portion is more in the middle.

Any ideas?