Does PyQt5/pyqt4 already supports QtVirtualKeyboard with Handwriting Recognition? - python

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

I been stuck with this too, and i am new to Qt
After some researching, and digging in source code, found the solution
You dont need to import it to use it since its a module it will implement itself to every qt input
Well you dont need to install it on PyQt5 but on Qt5 if it is not already come with your Qt package, if you use archlinux you can install it with pacman
pacman -S qt5-virtualkeyboard
If you cannot find it in you os repositories try to build it here is documantation
https://doc.qt.io/qt-5/qtvirtualkeyboard-index.html
Then to use it in your pyqt application, set environmental variable QT_IM_MODULE to "qtvirtualkeyboard" either from your bash or inside the top your script like
import os
os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"

Related

Python - Problem importing modules in VirtualEnv

I am trying to import PyQt5 by :
from PyQt5 import QtCore, QtGui, QtWidgets
But it is giving me the Error : Unable to import PyQt5. PyQt5 is definitely installed in the Virtualenv in the location -
"c:\users\TM\documents\python projects\pyqt test\env\lib\site-packages"
Which I did by - 'py -m pip install pyqt5' while in the (env).
My program is also in the 'pyqt test' folder.
I've installed Python on a new PC and this is the first time I'm having this problem, before I could just import anything in an env without any error.
EDIT: This is my sys.path:
['c:\\Users\\TM\\Documents\\Python Projects\\PyQt Test',
'C:\\Users\\TM\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
'C:\\Users\\TM\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
'C:\\Users\\TM\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
'C:\\Users\\TM\\AppData\\Local\\Programs\\Python\\Python38-32',
'C:\\Users\\TM\0\AppData\\Roaming\\Python\\Python38\\site-packages',
'C:\\Users\\TM\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages']

how to make the applications developed by pyqt5 support Chinese input on ubuntu

On ubuntu, I developed an application using pyqt5, but it does not support Chinese input(My sogouPinyin input method cannot show Chinese context menu when I want to type text on my application). My OS supports Chinese input. How to fix it?
install some packages.
sudo apt install fcitx-frontend-qt5 fcitx-libs-qt fcitx-libs-qt5
copy lib to pyqt folder.
sudo cp /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so ${PYTHON_HOME}/lib/site-packages/PyQt5/Qt/plugins/platforminputcontexts/
add os.environ['QT_IM_MODULE'] = 'fcitx' in main file. (maybe not necessary.)
reference
sogouPinyin is based on Fcitx, so for the case of Qt applications the docs indicates that you have to use the flag QT_IM_MODULE:
from PyQt5 import QtWidgets
if __name__ == '__main__':
import sys
import os
os.environ['QT_IM_MODULE'] = 'fcitx'
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
lay = QtWidgets.QVBoxLayout(w)
lay.addWidget(QtWidgets.QLineEdit())
lay.addWidget(QtWidgets.QTextEdit())
w.show()
sys.exit(app.exec_())
After the application is open you must place the focus in an editing widget such as QLineEdit, QTextEdit and press Ctrl + Space to enable it.
But you have to have installed fcitx-qt5 package:
On Ubuntu:
sudo apt-get install fcitx-qt5 fcitx fcitx-frontend-qt5

Python 3.7 Anaconda: "ImportError: cannot import name 'QtWebKitWidgets' from 'PyQt5'" [duplicate]

I've recently upgraded PyQt5 from 5.5.1 to 5.6.0 using the Windows 32-bit installer here: https://www.riverbankcomputing.com/software/pyqt/download5. I've also upgraded my python from 3.4 to 3.5.
When I run my old code (which used to work) with the latest version I get an exception:
from PyQt5.QtWebKitWidgets import *
ImportError: No module named 'PyQt5.QtWebKitWidgets'
All of my QT calls in my python occur consecutively and are (and I know I shouldn't be importing * but that's beside the issue here I think):
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKitWidgets import *
So the QtCore, QtGui and QtWidgets imports are all OK.
Also, when I search the source for QtWebKitWidgets there appears several references to this module.
Finally my python path looks like:
C:\PYTHON35;C:\PYTHON35\DLLs;C:\PYTHON35\LIB;C:\PYTHON35\LIB\LIB-TK;
and environment path:
C:\Python35\Lib\site-packages\PyQt5;C:\Python35;C:\Python35\Lib;C:\Python35\Lib\site-packages;C:\Python35\Scripts ....
QtWebKit got deprecated upstream in Qt 5.5 and removed in 5.6.
You may want to switch to PyQt5.QtWebEngineWidgets.QWebEngineView.
For basic use of PyQt5.QtWebKitWidgets.QWebView, it can simply be updated to use PyQt5.QtWebEngineWidgets.QWebEngineView in the source code, but there may be some differences in the new component which require further adjustments.
I was trying to run qutebrowser and it had the same error, the answer is simple, the packages changed.
You have two solutions:
1)
pip install PyQtWebEngine
2)
pip install PyQt5==5.11.3
Hope this helps any future problems
In PyQt5 "QtWebKitWidgets" is Deprecated. I just replace this line
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from PyQt5.QtWebKit import QWebSettings
With this code:
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView,QWebEnginePage as QWebPage
from PyQt5.QtWebEngineWidgets import QWebEngineSettings as QWebSettings
If you really want to use PyQt5.QtWebKitWidgets, you could run this from the command line:
pip install PyQtWebKit
and let it do what it does.
In PyQt5 "QtWebKitWidgets" is no longer available. Instead it is replaced with "QtWebEngineWidgets". So you have to make this change in your code.
For more information: http://doc.qt.io/qt-5/qtwebenginewidgets-qtwebkitportingguide.html

Installing SIP 4.16.4 and PyQt5.3.1 for Python 3.4 x64 on Windows 8.1

Downloaded SIP 4.16.4.zip(windows source) from riverbankcomputing - Unpacked and ran configure.py from within the folder. Sub-Directories sipgen, sip-lib are now in the Python34 directory along with sipconfig.py and Makefile.
I am unable to run any of the Makefiles either in the sipgen/sip-lib sub folders or in the main Python34 folder. Ran the installer for Py3.4-Qt5.3.1-x64 and the following test code from within PyCharm3.4.1
The code runs with exit code 0, but within the PyCharm editor, the import statements are flagged as
Cannot find reference 'QtCore' in '__init__.py'
and
Cannot find reference 'QtWidgets' in '__init__.py'
The Qt***.pyd (QWidget, QLabel, etc) files from:
Python34\lib\site-packages\PyQt5
used in the code are flagged by PyCharm as Unresolved reference.
My goal is to install PyQt5.3.1x64 for Python 3.4x64 on Windows 8.1 - I have searched extensively and most of the doc/posts I've encountered are for Visual Studio applications or leads off into some tangent that is not applicable.
I'm looking for a concise procedure to install on windows and am not sure if I should also install some base QT by running qt-opensource-windows-x86-1.6.0-6-online.exe installer.
I believe the problem is with not being able to run the make and make install steps for the Windows environment. There is a Makefile in each of the following directories...
Python34: python34\sipgen and python34\siplib
Do I need to run a make and install using each of these and if so how is this done on Windows 8.1?
TEST CODE
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Form(QWidget):
def \__init__(self, parent=None):
super(Form, self).\__init__(parent)
nameLabel = QLabel("Name:")
self.nameLine = QLineEdit()
self.submitButton = QPushButton("&Submit")
buttonLayout1 = QVBoxLayout()
buttonLayout1.addWidget(nameLabel)
buttonLayout1.addWidget(self.nameLine)
buttonLayout1.addWidget(self.submitButton)
self.submitButton.clicked.connect(self.submitContact)
mainLayout = QGridLayout()
# mainLayout.addWidget(nameLabel, 0, 0)
mainLayout.addLayout(buttonLayout1, 0, 1)
self.setLayout(mainLayout)
self.setWindowTitle("Hello Qt")
def submitContact(self):
name = self.nameLine.text()
if name == "":
QMessageBox.information(self, "Empty Field",
"Please enter a name and address.")
return
else:
QMessageBox.information(self, "Success!",
"Hello %s!" % name)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
screen = Form()
screen.show()
sys.exit(app.exec_())
In another post it was suggested that the unresolved references are caused by a bug in PyCharm. The code runs fine but the IDE sets flags throughout for all the Qt components. If anyone else is trying to install sip and Qt5 on windows 8 and needs help contact me and I will be glad to give step by step instructions using Visual Studio Developer Command Prompt.

PySide "hello world": py2exe/pyinstaller/cx_freeze and access violation

I am trying to build a very basic executable (Windows) using PySide. The following script runs properly in the interpreter (Python 2.7, PySide 1.1.2)
#!/usr/bin/python
import sys
sys.stdout = open("my_stdout.log", "w")
sys.stderr = open("my_stderr.log", "w")
import PySide.QtGui
from PySide.QtGui import QApplication
from PySide.QtGui import QMessageBox
# Create the application object
app = QApplication(sys.argv)
# Create a simple dialog box
msgBox = QMessageBox()
msgBox.setText("Hello World - using PySide version " + PySide.__version__)
msgBox.exec_()
I tried 3 methods (py2exe, pyinstaller and cx_freeze) and all the 3 generated executables fail to execute. The two stdout/stderr files appear, so I found the first PySide import is making everything fail. (Unhandled exception/Access violation)
I analyzed the executable file with depends (http://www.dependencywalker.com/) and everything looks correctly linked.
Any idea?
You need to add the atexit module as an include. source: http://qt-project.org/wiki/Packaging_PySide_applications_on_Windows
(is also the case for Linux btw)
Thank you for your help. Actually, this did not change anything :/ However, I found a solution to my problem: if I add from PySide import QtCore, QtGui, then the executable (with pyinstaller) does work!

Categories