問題描述
我正在使用 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_())
這篇關于PyQt5/pyqt4 是否已經支持帶有手寫識別的 QtVirtualKeyboard?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!