简体   繁体   English

如何在 Android 上的 QLineEdit 中关闭预测文本?

[英]How to turn off predictive text in QLineEdit on Android?

I'm trying to build an app for both android and linux using Qt 5.12.我正在尝试使用 Qt 5.12 为 android 和 linux 构建一个应用程序。 It's necessary to read the current text in QLineEdit every time a character is typed in. On Android 6 device the current text part shows underlined while typing and the predictor is shown.每次输入字符时都需要在QLineEdit中读取当前文本。在 Android 6 设备上,当前文本部分在键入时显示带下划线,并显示预测器。 I only get the signals QLineEdit::textChanged on every Space or Return .我只在每个SpaceReturn上收到信号QLineEdit::textChanged Same behavior for signals QLineEdit::textEdited QLineEdit::cursorPositionChanged .信号QLineEdit::textEdited QLineEdit::cursorPositionChanged的行为相同。 Disabling both QCompleter and QValidator didn't help.禁用QCompleterQValidator没有帮助。

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->lineEdit->setCompleter(nullptr);
    ui->lineEdit->setValidator(nullptr);
}


void MainWindow::on_lineEdit_textChanged(const QString &arg1)
{
    //just for demonstration
    ui->listWidget->addItem(arg1);
}

Qt 5.12.6 Android 6.0.1/Android 7.1.1 Google Keyboard Qt 5.12.6 Android 6.0.1/Android 7.1.1 谷歌键盘

Many thanks for your response!非常感谢您的回复!

For those who are interested or are facing the same problem: QLinedit::setInputMethodHints() is the right choice.对于那些有兴趣或面临同样问题的人: QLinedit::setInputMethodHints()是正确的选择。

    MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->lineEdit->setInputMethodHints(Qt::ImhNoPredictiveText|Qt::ImhNoAutoUppercase|Qt::ImhNoEditMenu);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM