簡體   English   中英

Qt/QML Android 3rd 方虛擬鍵盤不適用於 TextInput

[英]Qt/QML Android 3rd party virtual keyboard not working with TextInput

使用 Qt 5.2.1 部署簡單的測試應用程序時,Android 上的第 3 方虛擬鍵盤似乎無法正常工作? 我已經測試了所有可以接收文本輸入的項目,結果總是相同(TextInput、TextEdit 甚至 TextField 和 TextArea)我在我的 android 設備上使用SwiftKey 鍵盤,我只能輸入 1 個字符,下一個按鍵替換整個文本(即使在我按下一個鍵之前有超過 1 個字符),當按下空格鍵時,它會出現一個隨機鍵並且沒有空格,非常奇怪。 使用默認的 android 鍵盤,據我所知沒有問題,但我認為 3rd 方鍵盤在 android 上被廣泛使用,所以這可能是一個問題。

這是一個已知的錯誤還是我遺漏了什么?

設置“inputMethodHints: Qt.ImhNoPredictiveText”時效果更好,我可以輸入內容,但空格仍然不起作用,我還需要字典建議:) 因為我沒有任何其他 3rd 方鍵盤,我不知道問題僅在於 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,這是基於 qt 小部件的 gui 的一部分。 我遇到的問題是 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();
}

注意:不要浪費時間探索 focus 或 FocusScope。

作為一種解決方法,我使用 QQuickView 切換到完整的 QML 應用程序,該應用程序運行良好,但在按下數字鍵(0、1、2、3、...、9)時 TextInput 仍然沒有響應。

正在發生的事情以及在您的情況下可能發生的事情是,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 專家,但本周我遇到了這個問題。 正如我在谷歌上搜索的那樣,我發現它是一個錯誤,但我已經設法解決了這個問題。 這是我的方法,您可以自己實現類似的關鍵事件。

 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

希望這會幫助你,真誠的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM