[Solved] Remove Text Selection when QLineEdit gets focus.
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.
did you try using deselect(..) API of QLineEdit ?
Yes i tried that as well.....but still the text is getting highlighted in blue color..
You should subclass QLineEdit and re-implement focusInEvent.
class MyLineEdit : public QLineEdit
void focusInEvent(QFocusEvent *e)
Thanks for the reply. I tried the above code also as you suggested. But still it is not working.
Should i try the same with signal slot mechanism?
Kindly let me know if there is some other work around.
Tried with signal slot mechanism also but no luck ..
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.
Actually it is now working fine. Some other component was setting the
Because of that the behavior was not correct.
Now all is OK
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?