Not Responding when using PyQt - python

I just began to learn PyQt5 in python and the window which opens becomes not responding
import sys
import PyQt5
from PyQt5 import QtWidgets
from PyQt5 import QtCore
x=QtWidgets.QApplication(sys.argv)
y=QtWidgets.QWidget()
y.show()

Try adding the following line to the end of your code:
sys.exit(x.exec_())
I would also recommend following a tutorial such as this one as PyQt does have a framework which needs to be followed closely. (http://zetcode.com/gui/pyqt5/firstprograms/)

Related

Deallocation error of Matplotlib embeded in Pyside 2

I am executing this example file for matplotlib and I am getting the following error while exiting the mainwindow normally.
Fatal Python error: deallocating None
I have only changed the following lines, because i wanted to use PySide2 instead of PyQt.
Original:
# Make sure that we are using QT5
matplotlib.use('Qt5Agg')
from PyQt5 import QtCore, QtWidgets
New:
# Make sure that we are using QT5
matplotlib.use('Qt5Agg')
matplotlib.rcParams['backend.qt5']='PySide2'
from PySide2 import QtCore, QtWidgets
The program otherwise runs perfectly, it just crashes when i close it, which is a bit irritating.
My environment consists of:
Python 3.6.4
PySide2 5.6.0a1
MatplotLib 2.2.2
Any ideas?
Refer to this post https://stackoverflow.com/a/49712824/6704496, it appears a not up-to-date version bug. Please download the newest wheel http://download.qt.io/snapshots/ci/pyside/5.9/latest/.

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.

PyQt4 Application takes time on startup for the very fist time

I have developed an application using Python 2.7 and PyQt4.
Usually when I start my application it start within a second, but when I do start/restart my computer an than I start application for the very first time, It takes countable amount of time.
I did following module import to my application.
import cStringIO
import imp
import os
import sys
import taurus
import time
import traceback
from PyQt4 import QtCore
from PyQt4 import QtGui
from taurus.qt.qtgui.display import TaurusLabel
from taurus.qt.qtgui.util.ui import UILoadable
Then I have my main function as
if __name__ == "__main__":
logger.debug("In mainWindow - Executing Main function.")
app = QtGui.QApplication(sys.argv)
I tried using print statement and also checked time for every import.
Sometimes it takes time to import lines
from PyQt4 import QtCore
from PyQt4 import QtGui
and sometime
app = QtGui.QApplication(sys.argv)
takes too much time to execute.
I don't know why this strange behavior is happening.
My application is working on Ubuntu 16.04 and software version are PyQt4, Python 2.7, Taurus-4.1.1, PyTango 8.1.8,
This behavior happens only for the first time after start up of system. Please suggest something that I can tryout. I think this is some serious issue with the tool or application developed by me.
Any help is appreciated...
I dont know this would help, but try to minify the python code using PyMinifier.
Minfying and obfuscating helped one of my application.

TableView did not work when exe file

I made an application that uses sqlite3 and PyQt4. Until I convert my app to exe, tableView work properly. But then it did not work since it did not save changes or show changes. I used cxFreeze to convert my file. What's the problem here?
I also want to add that i am using this modules;
from PyQt4.QtSql import QSqlQueryModel,QSqlDatabase,QSqlQuery
from PyQt4 import QtCore, QtGui
import sqlite3 as sql
import os, time
And I guess the problem is QtSql, maybe? Because It handle the table and db things.

Difference between qt and PyQt4

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

Categories

Resources