03-QTWebEngine中使用qtvirtualkeyboard

qt提供了 virtualKeyboard 虚拟键盘模块,只需要在在main函数中最开始加入这样一句就可以了

qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

但是在使用的时候遇到了一些问题:

1、中文输入的时候没有输入提示

Qvirtualkeyboard使用及相关知识点_qtvirtualkeyboard-CSDN博客

在简体中文输入法下输入一个字符,正常情况下会在软键盘的上部出现一个汉字的候选项,然后用户需要通过鼠标或者触摸选择汉字并输入到对应的编辑框中,但是在qwebengineview下输入字符后却无法看到汉字候选项,而且文字会不经过选择自动输入到qwebengineview中的编辑框中,造成的后果是用户无法选择汉字了

解决方法:参考上面链接,修改 qtvirtualkeyboard-everywhere-src-5.15.2 的源码,然后重新编译

可以在qvirtualkeyboardinputcontext_p.cpp中的
void QVirtualKeyboardInputContextPrivate::update(Qt::InputMethodQueries queries)函数中,

注释掉
// update input engine
if ((newSurroundingText || newCursorPosition) &&
!testState(State::InputMethodEvent)) {
commit();
}
中的commit();语句即可,然后重新编译即可

2、键盘退出的时候发生段错误

问题排查:开始qtWeb浏览器程序是通过qtWidget调用 QWebEngine 控件来实现的,只是在main中加了 qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); 后面经排查发现只在 QWebEngine 中使用Qvirtualkeyboard 会有问题,在其他的比如 QMainWindow、QWidget中使用 Qvirtualkeyboard 都没问题。只能在QtQuick中使用WebEngineView控件来开启浏览器,而且要定义InputPanel才可以!!猜测可能是QTWidget的QWebEngine控件对QMl的Qvirtualkeyboard控件支持不好的原因吧!

下面是在QtQuick中使用WebEngineView控件来启动浏览器,使用InputPanel虚拟键盘

ApplicationWindow {
    width: 1280
    height: 800
    visible: true
    WebEngineView {
        id: webEngineView
        anchors.fill: parent
        url: "https://www.baidu.com"

        onNewViewRequested: {
           console.log(request.requestedUrl)
           url = request.requestedUrl
       }
        // // 加载完成后触发打印为 PDF
        // onLoadingChanged: {
        //     if (loadRequest.status === WebEngineView.LoadSucceededStatus) {
        //         webEngineView.printToPdf("output.pdf")
        //     }
        // }
        onLinkHovered: {

        }
    }

    InputPanel {
        id: inputPanel
        z: 99
        x: 0
        y: parent.height
        width: parent.width
        // externalLanguageSwitchEnabled:true
        states: State {
            name: "visible"
            when: inputPanel.active
            PropertyChanges {
                target: inputPanel
                y: parent.height - inputPanel.height
            }
        }
        transitions: Transition {
            from: ""
            to: "visible"
            reversible: true
            ParallelAnimation {
                NumberAnimation {
                    properties: "y"
                    duration: 250
                    easing.type: Easing.InOutQuad
                }
            }
        }
        onActiveChanged: {//当输入框活跃状态改变的时候

        }
        Component.onCompleted: {
            // VirtualKeyboardSettings.styleName = "retro"
            VirtualKeyboardSettings.activeLocales = ["en_US", "zh_CN"]
        }
    }
}

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在静态编译 Qt 的时候,需要使用 Qt 的 configure 工具指定静态编译的选项,包括需要编译的模块等。如果你想要静态编译 Qt Multimedia 模块,可以通过以下步骤实现: 1. 下载 Qt 源代码,并解压缩到一个目录。 2. 打开命令行终端,进入 Qt 源代码目录。 3. 执行以下命令,进行静态编译配置: ``` configure -static -prefix C:\Qt\Qt5.14.2\static -release -platform win32-g++ -no-openssl -no-compile-examples -nomake tests -nomake examples -skip qtwebengine -skip qtwayland -skip qtwebview -skip qtwebchannel -skip qtwebsockets -skip qtvirtualkeyboard -skip qtlocation -skip qtscript -skip qtserialbus -skip qtserialport -skip qtscxml -skip qtremoteobjects -skip qtdatavis3d -skip qtcharts -skip qtnetworkauth -skip qtwebglplugin -skip qtpurchasing -skip qtgamepad -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtvirtualkeyboard -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip qtwebglplugin -skip qtandroidextras -skip qtmacextras -skip qtwinextras -skip qtsensors -skip qtcanvas3d -skip qt3d -skip qtquickcontrols2 -skip qtquicktimeline -skip qtquick3d -skip qtquick3dassimpsceneio -skip qtquick3drender -skip qtquick3danimation -skip qtquick3dinput -skip qtquick3dlogic -skip qtquick3dextras -skip qtwebview -skip qtwebengine -skip qtdocgallery -skip qtfeedback -skip qtconnectivity -skip qtwebengine -skip qtwebview -skip qtspeech -skip qtpim -skip qtwayland -skip qtwebsockets -skip qtopcua -skip qtvirtualkeyboard -skip qtremoteobjects -skip qtsensors -skip qtwebview -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtscript -skip qtscxml -skip qtnetworkauth -skip qtpurchasing -skip

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值