PDA

View Full Version : QLineEdit shows always the end, how shows start ?



Alundra
3rd January 2015, 17:09
Hi,
QLineEdit always shows the end when focus out or when text changed (if I don't miss one).
Is it possible to change the behavior to always shows the start instead of end ?
How to achieve this result ?
Thanks for the help

ChrisW67
3rd January 2015, 20:45
If you want the text aligned to the left then don't change the default alignment (which shows the start of the string). You change this using QLineEdit::setAlignment() (http://qt-project.org/doc/qt-4.8/qlineedit.html#alignment-prop) or the property editor in Qt Designer.

Alundra
3rd January 2015, 22:06
This screenshot shows better the problem :
http://zupimages.net/up/15/01/rgnm.png
The text is not shown from the start.

wysota
3rd January 2015, 22:30
Where does this horizontal line come from?

Alundra
3rd January 2015, 23:34
That's me, I added "_________________" at the end of the text to show the behavior of QLineEdit which is not wanted here.
The wanted behavior is to show the start of the QLineEdit on the focus-out and when text changed, in other words, never show the end but the start.
The only option is to make a custom QLineEdit nammed "ShowStartLineEdit" to do this behavior or Qt has an option to do that ?

wysota
3rd January 2015, 23:39
You can override the events and set cursor position to 0, however I don't know why you'd want to do that.

Alundra
4th January 2015, 00:00
Because you always see the end of the value, for a translation for example, you better want to see the start, same for the name of an element, you want to see the start.
You can see on this screenshot, you can't know the value since you only see the end.
http://zupimages.net/up/15/01/j0jz.png

wysota
4th January 2015, 08:48
To be honest I don't see what it changes to see the beginning. If you don't know whether the value is "1234" or "12345" what's the benefit? Usually you'd just see the full value in a tooltip while hovering over the item or you'd make sure the whole value fits into the visible area.

Rajesh.Rathod
19th June 2015, 12:09
I had same issue and I solved it by calling setCursorPosition(0); after set text.