Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Limit typing of characters in android virtual keyboard when using QLineEdit
Forum Updated to NodeBB v4.3 + New Features

Limit typing of characters in android virtual keyboard when using QLineEdit

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 3 Posters 365 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheCrowKaka
    wrote on last edited by
    #1

    Hello,

    Tried searching a lot for some method to limit the typing of characters in a QLineEdit on Android. Using Qt5.15.2. Using QtWidgets for crossplatform compatibility.

    I am using QLineEdit, I set the maxlength to say for example 15. WHen I type the characters in android on screen keypad, it lets user type as many characters as they type and truncates to 15 digits on pressing Spacebar or Enter key.

    Tried setting the setInputMethodHints(Qt::ImhNoPredictiveText|Qt::ImhNoAutoUppercase|Qt::ImhNoEditMenu);
    as I got during my search exercise, but did not work.

    textChanged signal on this QLineEdit also works only when space or enter is typed and not for each character.

    Is there a way to do this? Maybe by using the JNI method?

    A Qt Enthusiastic...

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bartlomiej Moskal
      wrote on last edited by
      #2

      The problem that you described here is related with predictions. Android keyboard have a feature that allows to choose whole ready word rather than type it letter by letter. That's why the typed word is underlined. As the underlined part is still "under construction" and can be changed in any other word (by predictions). This (underlined) part is kept in preeditText - while editText still not changed.

      You can just turn predictions off. There are two possibilities to do it:

      • Set inputMethodHints to Qt.ImhNoPredictiveText | Qt.ImhSensitiveData

      • Set QT_ANDROID_ENABLE_WORKAROUND_TO_DISABLE_PREDICTIVE_TEXT environment variable: qputenv("QT_ANDROID_ENABLE_WORKAROUND_TO_DISABLE_PREDICTIVE_TEXT", "1"); )
        and inputMethodHints to ImhNoPredictiveText

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bartlomiej Moskal
        wrote on last edited by
        #3

        These solutions are for QML rather than QWidgets, but still - you can give it a try

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved