Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QLineEdit is overwriting the first input character (bug?)



  • Hello,

    I have been working with QT for and Android development.

    I have a problem with QLineEdit widgets. If the textbox is empty, because of the first time or I removed the previous text, when I write then the first character becomes highlighted so if I write another character I overwrite the first character.

    I have disabled several android features like "text-autocomplete", besides in QLineEdit property imhNonPredictiveText = true

    • Android version 9
    • QT 5.12.0 building for android_armv7

    How to reproduce:
    In a QLineEdit, remove all the characters using backspace, once it is empty, press backspace one or more times. Then write a character, it might be highlighted (selected).

    Mitigation:
    This is the way we are mitigating this problem, but we would like to if this is a known problem or a configuration problem, and how to solve it without using something like this:

    
    // QLineEdit bug fix
    connect(ui->qlineeditWidget, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(resetQLineEditSelectionIssue(int,int)));
    
    
    void FrmWifiSettings::resetQLineEditSelectionIssue(int oldPos, int newPos)
    {
    	QObject * senderObj = sender();
    
    	if (senderObj != nullptr)
    	{
    		QLineEdit *widget = (QLineEdit*) senderObj;
    
    		if ( (widget != nullptr) && (oldPos == 0) && (newPos == 1) && (widget->hasSelectedText()) )
    		{
    			qDebug() << "resetQLineEditSelectionIssue() : issue found ";
    			widget->deselect();
    		}
    	}
    }
    

    Thanks


  • Lifetime Qt Champion

    @Hector_WPG You should check Qt bug tracker. If it is not known issue there you can file a bug.


  • Lifetime Qt Champion

    @jsulm That is correct, but I'd first try with the latest Qt 5 version 5.15.2

    Regards