How to get a QPoint from a cursor position in QLineEdit
-
Maybe "QLineEdit::cursorRect() ":http://doc.qt.nokia.com/stable/qlineedit.html#cursorRect is of use for you (the cursor is a shape and does not have a "point" property). Be aware, the method is protected, you will have to subclass QLineEdit in order to access it.
-
I am curious: What do you want to do with the QPoint value?
I think the only way to get an approximation of this information is to use QFontMetrics to calculate the positions of the individual characters...
-
The cursor position is relative to the start of the text. If your cursor is at the beginning of the text (i.e. before the very first character or with an empty text), it is < 0 (platform dependend), if you move the cursor, the rect moves and the x position is the pixel(s) between the two characters where the cursor is positioned. Everything works for me.
-
if you need the text width, try other solutions
http://doc.qt.nokia.com/4.7/qfontmetrics.html