In the following snippet, PyQt5 behaves different from PyQt4 and PySide. In PyQt5 when you press the button, 'None' is printed to the console, which means the signal was not disconnected when the widget was deleted. In PyQt4 and PySide everything is fine and nothing is printed out, i.e. the signal got disconnected. Is this a bug or am I doing something wrong? I have PyQt5 v5.7.0.
import sys
from PyQt5 import QtCore, QtWidgets # for PyQt5
#from PyQt4 import QtCore, QtGui # for PyQt4
#from PySide import QtCore, QtGui # for PySide
#QtWidgets = QtGui # for PySide and PyQt4
class MyWidget(QtCore.QObject):
def doChange(self):
print(self)
app = QtWidgets.QApplication([])
w = MyWidget()
button = QtWidgets.QPushButton("Push me")
button.clicked.connect(w.doChange)
del w
button.show()
sys.exit(app.exec_())
UPDATE: Moreover this issue is observable only on Linux. Windows seems to work fine. Seems this is a bug.
Related
I want to use pyqt4 on python35. However, the latest official release supports py=<34
So I found this university website https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4
which unofficially extended support for later versions including python35
My problem is that QsciScintilla is not working. I tried to run this code:
import sys
from PyQt4.QtGui import QApplication
from PyQt4 import QtCore, QtGui, Qsci
from PyQt4.Qsci import QsciScintilla
if __name__ == "__main__":
app = QApplication(sys.argv)
editor = QsciScintilla()
editor.show()
sys.exit(app.exec_())
The window becomes unresponsive then crashes:
Process finished with exit code -1073740771 (0xC000041D)
The reason I want to use pyqt4 on python3.5 is that I have a quit big application built on pyqt4
and I want to upgrade python version of the project to 35
I moved to PyQt5. It is always not a good idea to use an unofficial package.
I got this error on PyCharm
Traceback (most recent call last)
from import QtCore, QtGui, QtWidgets ModuleNotFoundError: No module named 'PyQt5'
this is the import statement
from PyQt5 import QtCore, QtGui, QtWidgets
Although that I have checked the library in terminal using pip3 command and it works.
Also, I have configured manually the interrupter to be with python3 but still the error not resolved. Any idea of solving this issue?
I'm trying to load a Qt5 file in a bundle on a Mac.
#!/usr/bin/env python
from PyQt5.QtWidgets import (QApplication, QMainWindow)
from PyQt5 import uic
import sys
import os
MainUI = os.path.dirname(os.path.realpath(__file__)) + "/data/MainUI.ui"
Ui_MainWindow, QtBaseClass = uic.loadUiType(MainUI)
class MyForm(QMainWindow,Ui_MainWindow):
def __init__(self):
QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MyForm()
w.show()
sys.exit(app.exec_())
This works fine in the commandline but when I bundle this with pyinstaller the program aborts because it can't find the file mainUI.ui. I found this solution but I can't get it working (resource_path function not found).
I've made another and that worked fine but this one (a one file program) I can't get working.
Edit:
I stopped trying to fix this and went for the multiple file solution: 1 file to startup and one for the PyQt functions. That works 100%.
When I use QtDesigner and pyuic5 for PyQt5 GUI applications it always uses imports like this:
from PyQt5 import QtCore, QtWidgets
class Ui_TabWidget(object):
def setupUi(self, TabWidget):
TabWidget.setObjectName("TabWidget")
TabWidget.resize(950, 188)
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
...
Is it possible to configure QtDesigner or pyuic5 to have it like this:
from PyQt5.QtWidgets import QWidget
I don't want to import everything from QtWidgets to keep my compiled binaries smaller. However, if I edit the file by myself it will lose all the changes if I change the GUI via QtDesigner in the future.
guys
I recently heard about PyQt4 and decided I should give it a try, however, importing gave me some errors. When I tried importing QtCore and QtGui, I received this error:
from PyQt4 import QtCore, QtGui
ImportError: DLL load failed: The specified module could not be found.
I am using python 3.6.0 on my windows 32 bit computer
I installed pyqt4 by using
pip install pyqt4-4.11.4-cp36-cp36m-win32.whl
To solve this problem I looked into my site-packages and I did see
You should use PyQt5. I know it doesn't have QWebView, but it has a extra module called QWebEngineView. You can install it by running this in the terminal:
pip install PyQtWebEngine. This is the code I use:
import sys
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication
url = "https://stackoverflow.com/"
app = QApplication(sys.argv)
web = QWebEngineView()
web.load(QUrl(url))
web.setZoomFactor(2)
web.zoomFactor()
web.show()
sys.exit(app.exec_())