[Solved] Remove Text Selection when QLineEdit gets focus.
-
Hello All,
I am using QT 5.3.2 in Fedora Core 13. There is a one QLineEdit present in the QWidget. Whenever i click on the QLineEdit, all the text present in it becomes selected with blue color highlight. Is there any way to remove this behavior?
I dont want any of the text selection on focus of the QLine Edit.
Kindly help.
Thanks
-
did you try using deselect(..) API of QLineEdit ?
-
Hi,
You should subclass QLineEdit and re-implement focusInEvent.
Something like
@
class MyLineEdit : public QLineEdit
{
protected:
void focusInEvent(QFocusEvent *e)
{
QLineEdit::focusInEvent(e);
deselect();
}
};
@ -
The reasons SGaist suggestion might not work either
when something else (not focusInEvent ) selects it or selectAll slot is executed through event loop.
In such case instead of deselect() call you may try to emit the custom signal which you can connect to deselect slot with Qt::QueuedConnection connection type.Also I want to say that this is bug anyway. Selection should not be changed on focus in. And this was not happening in Qt 4.
-
Hi
Trying similar functionality with QTableWidgetItem. I need a MS Excel like functionality. On pressing Alt + enter, The cursor should go o next line, and the text already entered should not be selected.QTableWidgetItem is not a sub class of QWidget, so how to approach?
Thanks