Does PyQt5/pyqt4 already supports QtVirtualKeyboard with Handwriting Recognition?

前端 未结 2 1932
盖世英雄少女心
盖世英雄少女心 2021-01-24 19:56

I\'m working on a desktop application using pyqt5, and I want to use a Virtual Keyboard with Handwriting Recognition. I saw that Qt, QtVirtualKeyboard already support it.

<
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-24 20:24

    for qt desinger you can add only this line on your .py file.

    os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"
    

    but If you want use QML with qtvirtualkeyboard;

    There is no virtualkeyboard plugin in pyqt5.8, you must be use qt's paths.

    For a example, basic steps for pyqt5, qt5.8 and qtvirtualkeyboard installiation on ubuntu:

    1.step install qt5.8 with qtvirtualkeyboard

    wget http://download.qt.io/official_releases/qt/5.8/5.8.0/qt-opensource-linux-x64-5.8.0.run

    chmod +x qt-opensource-linux-x64-5.8.0.run

    ./qt-opensource-linux-x64-5.8.0.run

    2.step

    apt-get install python3 python3-pip pip3 install pyqt5

    3.step

    set environmental variables your qt paths on your python code.

    import sys, os
    os.environ["QT_DIR"] = "/opt/Qt5.8.0/5.8/gcc_64"
    os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = "/opt/Qt5.8.0/5.8/gcc_64/plugins/platforms"
    os.environ["QT_PLUGIN_PATH"] = "/opt/Qt5.8.0/5.8/gcc_64/plugins"
    os.environ["QML_IMPORT_PATH"] = "/opt/Qt5.8.0/5.8/gcc_64/qml"
    os.environ["QML2_IMPORT_PATH"] = "/opt/Qt5.8.0/5.8/gcc_64/qml"
    os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"
    
    #print(os.environ) 
    
    from PyQt5.QtCore import *
    from PyQt5 import QtCore
    from PyQt5.QtWidgets import *
    from PyQt5.QtQuick import *
    
    
    class keyboardapp(object):
        def __init__(self):
            self.view = QQuickView()
            self.view.setObjectName("View")
            #self.view.setFlags(Qt.FramelessWindowHint)
            self.view.setSource(QUrl("main.qml"))
            self.view.setResizeMode(QQuickView.SizeRootObjectToView)
            #self.Screen = self.view.rootObject()
            #print("Screen(Root) = " + str(self.Screen))
            self.view.show()
    
    app = QApplication(sys.argv)
    test = keyboardapp()
    sys.exit(app.exec_())
    

提交回复
热议问题