Difference between qt and PyQt4 - python

Well I am new to Qt and found its easier to work with python , I dont know how far its true .
but some of the code snippets have
import qt
and some have
import PyQt4
I don't know what the difference is, when I tried to interchange them I did get some errors , like some function was not recognizable and so on, also I am trying to build front end GUI for my application, which GUI framework would u suggest ? Is there anything close to VB like environment ?

Old PyQt3 use qt
import qt
Current PyQt4 use PyQt4
import PyQt4
If you use PySide, use PySide
import PySide

Related

ModuleNotFoundError: No module named 'QWebEngineView'

I have been using the QT designer tool which saves GUIs as a XML template. PySide2 is able to covert this to a Python Class file.
Utilizing the tool for an XML that includes QWebEngineView
pyside2-uic GUI_NEW.ui > ui_main.py
The first few lines of the ui_main.py call for
################################################################################
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from QWebEngineView import QWebEngineView
running the file that utilizes this, results in:
ModuleNotFoundError: No module named 'QWebEngineView'
So far I have tried
Trying PySide6 over PySide 2
Replaced the import line with
from PySide2.QtWebEngineWidgets import QWebEngineView
The Application runs but completely hangs
pip install PyQtWebEngine
pip install PyQt5==5.11.3
Cleaning up, installing all references to Qt (Pyside, PyQT, etc), and re-installing
Attempted all the above on python 3.6 - 3.8
Here is another option, you don't have it.
Then try this option:
from PyQt5 import QtWebEngineWidgets
That is, an example of a string:
self.webView = QtWebEngineWidgets.QWebEngineView(self.centralwidget)
But, unfortunately Qt, PyQt and PySide should never be used together. Most problems occur when trying to re-display a widget created with a binding with another one created with a different binding.
The solution is simple: you either use PyQt5 and use QtWebEngineWidgets, or PySide2.
As a last resort, try installing a newer version (5.12)(PyQt5) and install PyQtWebEngine separately.
Ultimately I stuck to PySide2 (option 2), creating a new project specific python environment that did not involve PyQt5. This prevented the application from hanging with zero console errors.

Qt WebEngine seems to be initialized

When I run my Qt application I get the message
Qt WebEngine seems to be initialized from a plugin. Please set
Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute before
constructing QGuiApplication.
The app runs fine regardless of the fact that this is getting dumped to the terminal. I cant seem to find the root cause or really understand what this message is trying to tell me. What is this message saying and how can I fix it?
This can be fixed by setting AA_ShareOpenGLContexts before Spawning the QApplication.
See below an example when using PySide2
from PySide2 import QtCore, QtWidgets
if __name__ == '__main__':
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
qt_app = QtWidgets.QApplication(sys.argv)
NB: As mentioned as reply in the question: When using PyQt5, checkout https://bugreports.qt.io/browse/QTBUG-51379 instead
...
Using PySide6 instead of PySide2 solved my problem with python 3.9 and QT 5.15 if it can help

PyCharm PyQt4 / PyQt5 collision in debug mode

I am trying to use PyQt4 in pycharm. My code works perfectly in run mode, but in debug mode, when I try to import PyQt4 I get the following error:
"RuntimeError: the PyQt4.QtCore and PyQt5.QtCore modules both wrap the QObject class"
This happens even w/ very barebones code:
from PyQt4 import QtGui, QtCore
print('cheese')
(thus, this is different from previous PyQt4 Pycharm problems w. Matplotlib)
Clearly, the PyCharm debugger is using PyQt5 (this can be seen by calling sys.modules['PyQt5']). How can I 'un-import' PyQt5, or at least prevent the collision?
Also: I tried importing differently to include explicit dependencies, but this also gives error:
import PyQt4 as pp
pp.QtGui
AttributeError: module 'PyQt4' has no attribute 'QtGui'
Thanks!
you can go to Settings>Build,Execution,Deployment>Debugger>Python Debugger>PyQt compatible:
Select PyQt4.
Try going to File > Settings > Project > Project Interpreter. Edit your current interpreter, or create a new one, and remove PyQt5 from the list that shows up.

How to show a webpage in Qmainwindow?

I have searched entire web to find a way to do this.
All the answers are about PyQt4, Pyside, Qwebview, Qt4, or Qt5(C++), therefore they do not work on PyQt5.
the other answer is QtWebEngineView: unknown for PyQt5 (at least mine).
I have the latest version of Python, Pycharm and PyQt5.
Tnx All. The correct import was from PyQt5 import QtWebEngineWidgetsthen, you can use QWebEngineVieweasily by load() method.

problem with import qt in python

I want to use qt with python.
"import qt" return me :"ImportError: No module named qt". I already instaled pyqt.
what I hve to install in order to activate "import qt"
Thank You
The current PyQt comes in the PyQt4 package, which has several modules. You almost always need to start with:
from PyQt4 import QtCore
from PyQt4 import QtGui
Add other imports as necessary if you need additional sub-modules of PyQt (like QtNetwork, QtSql etc).
Tip for the future: find the lib/site-packages library of your Python installation and look at the packages in there if you're not sure about the name after installing.
Also, arm yourself with a PyQt tutorial - any decent one covers this in the first few paragraphs.
import PyQt4 works for me fine.

Categories

Resources