Qt/QML Android第三方虚拟键盘不支持TextInput



似乎android上的第三方虚拟键盘在部署Qt 5.2.1的简单测试应用程序时不能正常工作?我已经测试了所有项目,可以接收文本输入,总是相同的结果(texttinput, texttedit,甚至TextField和TextArea)我在我的安卓设备上使用SwiftKey键盘,我只能输入1个字符,下一个按键替换整个文本(即使在我按下一个键之前有超过1个字符),也在按空格键时,它出现一个随机的键,没有空间,非常奇怪。据我所知,默认的android键盘没有问题,但我认为第三方键盘在android上被广泛使用,所以这可能是个问题。

这是一个已知的错误还是我错过了什么?

当设置"inputMethodHints: Qt.ImhNoPredictiveText"它工作得更好,我可以输入的东西,但空间仍然不工作,我也想字典建议:)因为我没有其他的第三方键盘,我不知道问题是否只出现在SwiftKey上,但这是商店里最好的键盘之一。

代码示例:

import QtQuick 2.2
Rectangle {
    width: 360
    height: 360
    TextInput {
        anchors.fill: parent
        font.pointSize: 20
        text: "type here"
        //inputMethodHints: Qt.ImhNoPredictiveText
    }
}

我还在控制台输出中得到这些警告:

W/IInputConnectionWrapper( 8703): getExtractedText on inactive InputConnection
W/IInputConnectionWrapper( 8703): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 8703): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 8703): getTextAfterCursor on inactive InputConnection

应该在Qt 5.3.0 RC1中修复。目前Qt 5.3已经发布,所以值得一试。

我目前使用QT5.5.1为android应用程序,仍然有一个问题与TextInput控件捕获某些键盘事件。

最初我在QQuickWidget中显示我的QML,这是基于gui的qt widgets的一部分。我遇到的问题是,QML TextInput项目没有收到来自android键盘的按键事件。

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{

=====================================================================

#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QFile file(":/styles/app_style.css");
    file.open(QFile::ReadOnly);
    QString styleSheet = QString::fromLatin1(file.readAll());
    a.setStyleSheet(styleSheet);
    MainWindow w;
    w.statusBar()->setHidden(true);
    w.show();
    return a.exec();
}

注意:不要浪费时间探索焦点或FocusScope。

作为变通办法,我使用QQuickView切换到一个完整的QML应用程序它工作得很好,除了文本输入仍然没有响应什么时候数字键(0,1,2,3,…)

在你的情况下发生的和可能发生的是,数字键的按键事件和第三方键盘按键事件正在被QQuickView keyPressEvent处理程序拾取。

= = = = = = mainwindow.h ======================================================

class MainWindow : public QQuickView
{
    Q_OBJECT
public:
    explicit MainWindow(QWindow  *parent = 0);
    ~MainWindow();
    void keyPressEvent(QKeyEvent *event);

= = = = = = mainwindow.cpp ===================================================

void MainWindow::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Back)
    {
        qDebug() << "[[Back button]]";

= = = = = = main.cpp =========================================================

int main(int argc, char *argv[])
{
    QGuiApplication app(argc,argv);
    MainWindow view;
    view.show();
    return app.exec();
}

======================================================================

我不是Qt专家,但我本周遇到了这个问题。尽管我在谷歌上搜索了很多,但我发现这是一个bug,但我已经设法解决了这个问题。以下是我的方法,您可以自己实现类似的关键事件。

 Item {
        Layout.fillHeight: true
        Layout.fillWidth: true
        id: rectDomain
        Rectangle {
            anchors.fill: parent
            anchors.margins: 2 * Screen.pixelDensity
            border.width: 1
            border.color: "#916E34"
            TextEdit {
                id: txtDomain
                property int lastCursorIndex: 0
                anchors.fill: parent
                horizontalAlignment: Qt.AlignHCenter
                verticalAlignment: Qt.AlignVCenter
                font.pointSize: 16
                text: controller.domain //"192.168.20.57"
                inputMethodHints: Qt.ImhNoPredictiveText
                //                    wrapMode: TextEdit.WrapAnywhere
                //                    color: "#0B151E"
                focus: true
                Keys.onReleased: {
                    if (event.key == Qt.Key_Backspace)
                    {
                        txtDomain.lastCursorIndex = txtDomain.selectionStart
                        console.log("Selection Test... Selection Start : " + txtDomain.lastCursorIndex + "Selection End" + txtDomain.selectionEnd)
                        if (txtDomain.selectionStart == txtDomain.selectionEnd) // Remove single character
                        {
                            text = text.substring(0, cursorPosition-1) + text.substring(cursorPosition, text.length)
                            cursorPosition = txtDomain.lastCursorIndex- 1
                        }
                        else                                                        // Remove selected part from text.
                        {
                            text = text.substring(0, txtDomain.selectionStart) + text.substring(txtDomain.selectionEnd, text.length)
                            cursorPosition =  txtDomain.lastCursorIndex
                        }
                    }
                    else
                        console.log("It is not the Backspce... Might be Space Enter UppoerCase, Change Language Button")
                }
            }
        }
    }

只是一个提示,在我的方法中,我需要在摆脱它们之前选择部分。所以我需要设置focus:true

希望这对你有帮助,真诚。

最新更新