PyQt5/pyqt4 是否已经支持带有手写识别的 QtVirtualKeyboard?

2022-01-12 00:00:00 python pyqt pyqt5 pyqt4 qtquick2

问题描述

我正在使用 pyqt5 开发桌面应用程序,我想使用带有手写识别功能的虚拟键盘.我看到Qt,QtVirtualKeyboard已经支持了.

这里是

我得到了在 QtCreator 上运行的 C++ Qt 示例代码.但是使用 python3.5 和 PyQt5 会给出这样的信息:

模块QtQuick.VirtualKeyboard"未安装导入 QtQuick.VirtualKeyboard 2.1

我应该如何从这里继续?PyQt5 是否带有 VirtualKeyboard 模块?如果没有,如何在 PyQt5 上安装?

解决方案

对于 qt desinger,您只能在 .py 文件中添加这一行.

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

但是如果你想使用 QML 和 qtvirtualkeyboard;

pyqt5.8没有虚拟键盘插件,必须使用qt的路径.

例如,在 ubuntu 上安装 pyqt5、qt5.8 和 qtvirtualkeyboard 的基本步骤:

1.step 用qtvirtualkeyboard安装qt5.8

<块引用>

wgethttp://下载.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 安装 python3 python3-pippip3 安装 pyqt5

3.step

在你的python代码上设置你的qt路径的环境变量.

导入系统,操作系统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)从 PyQt5.QtCore 导入 *从 PyQt5 导入 QtCore从 PyQt5.QtWidgets 导入 *从 PyQt5.QtQuick 导入 *类键盘应用程序(对象):def __init__(self):self.view = QQuickView()self.view.setObjectName("视图")#self.view.setFlags(Qt.FramelessWindowHint)self.view.setSource(QUrl("main.qml"))self.view.setResizeMode(QQuickView.SizeRootObjectToView)#self.Screen = self.view.rootObject()#print("屏幕(根) = " + str(self.Screen))self.view.show()应用程序 = QApplication(sys.argv)测试 = 键盘应用程序()sys.exit(app.exec_())

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.

Here's a link!

I got the C++ Qt example code running on QtCreator. But using python3.5 and PyQt5 it gives this message:

module "QtQuick.VirtualKeyboard" is not installed 
 import QtQuick.VirtualKeyboard 2.1 

How should I go on from here? Does PyQt5 comes with VirtualKeyboard module? if no How to install it on PyQt5?

解决方案

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_())

相关文章