selecting text using qlineedit while changing focus
-
Looking for a way to select all the text in a qlineedit when it gains focus. I have it being able to select the text right now, but if the focus is in another field the text remains selected.
-
Hi,
You can subclass QLineEdit, reimplement the focusInEvent function and call selectAll in it
Hope it helps
-
@SGaist OK, but when I would call this function what type would the parameter 'e' have to be? The function that it's being called in takes the qt object as a parameter. Could I use that as the parameter of this overloaded function? I just don't have much experience with using events.
-
You don't call that function, it's called for you when the widget gets focus.
void MyCoolLineEdit::focusInEvent(QFocusEvent * e) { selectAll(); }
Should be all you need
-
@SGaist strange results seemingly. When the line edit receives focus, the cursor stops blinking and the selectAll() function is used, however no text is selected. The cursor is stationary at the end of the text
-
Ho are you setting the focus on the QLineEdit ?