Clear all widgets in a layout in pyqt

After a lot of research (and this one took quite time, so I add it here for future reference), this is the way I found to really clear and delete the widgets in a layout: for i in reversed(range(layout.count())): layout.itemAt(i).widget().setParent(None) What the documentation says about the QWidget is that: The new widget is deleted when … Read more

How do I compile a PyQt script (.py) to a single standalone executable file for windows (.exe) and/or linux?

if you want completelly create one stand alone executable, you can try PyInstaller . i feel it’s better to create one stand alone executable than cx_freeze or py2exe (in my experience). and easy to use (full documentation available in the site). It supports Python 3.6 or newer. Pass the –onefile argument if you want to … Read more

Should wildcard import be avoided?

The answer to your question’s title is “yes”: I recommend never using from … import *, and I discussed the reasons in another very recent answer. Briefly, qualified names are good, barenames are very limited, so the “third option” is optimal (as you’ll be using qualified names, not barenames) among those you present. (Advantages of … Read more

PyQt4.QtCore.pyqtSignal object has no attribute ‘connect’

I had the same exact problem as you. Try moving self.parse_triggered = QtCore.pyqtSignal() out of your constructor but inside your class declaration. So instead of it looking like this: class Worker(QtCore.QThread): def __init__(self, parent = None): super(Worker, self).__init__(parent) self.parse_triggered = QtCore.pyqtSignal() It should look like this: class Worker(QtCore.QThread): parse_triggered = QtCore.pyqtSignal() def __init__(self, parent = … Read more

Unable to load files using pickle and multiple modules

The issue is that you’re pickling objects defined in Settings by actually running the ‘Settings’ module, then you’re trying to unpickle the objects from the GUI module. Remember that pickle doesn’t actually store information about how a class/object is constructed, and needs access to the class when unpickling. See wiki on using Pickle for more … Read more

How to embed matplotlib in pyqt – for Dummies

It is not that complicated actually. Relevant Qt widgets are in matplotlib.backends.backend_qt4agg. FigureCanvasQTAgg and NavigationToolbar2QT are usually what you need. These are regular Qt widgets. You treat them as any other widget. Below is a very simple example with a Figure, Navigation and a single button that draws some random data. I’ve added comments to … Read more

Background thread with QThread in PyQt

I created a little example that shows 3 different and simple ways of dealing with threads. I hope it will help you find the right approach to your problem. import sys import time from PyQt5.QtCore import (QCoreApplication, QObject, QRunnable, QThread, QThreadPool, pyqtSignal) # Subclassing QThread # http://qt-project.org/doc/latest/qthread.html class AThread(QThread): def run(self): count = 0 while … Read more