PyQt5 / pyqt4中使用虚拟键盘QtVirtualKeyboard

2

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

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

但是如果您想将QML与qtvirtualkeyboard一起使用;

pyqt5.8中没有virtualkeyboard插件,您必须使用qt的路径。

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

1.步骤使用qtvirtualkeyboard安装qt5.8

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.步骤

apt-get安装python3 python3-pip pip3安装pyqt5

第三步

在python代码上设置环境变量qt路径。

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

 

参考地址:链接

你可能感兴趣的:(qt)