How to reconstruct a .ui file from pyuic .py file

It is possible to do this using QFormBuilder: from PyQt4 import QtCore, QtGui, QtDesigner from myui import Ui_Dialog def dump_ui(widget, path): builder = QtDesigner.QFormBuilder() stream = QtCore.QFile(path) stream.open(QtCore.QIODevice.WriteOnly) builder.save(stream, widget) stream.close() app = QtGui.QApplication([”]) dialog = QtGui.QDialog() Ui_Dialog().setupUi(dialog) dialog.show() dump_ui(dialog, ‘myui.ui’) (NB: showing the window seems to be quite important in order to get the … Read more

Linking a qtDesigner .ui file to python/pyqt?

Another way to use .ui in your code is: from PyQt4 import QtCore, QtGui, uic class MyWidget(QtGui.QWidget) … #somewhere in constructor: uic.loadUi(‘MyWidget.ui’, self) both approaches are good. Do not forget, that if you use Qt resource files (extremely useful) for icons and so on, you must compile it too: pyrcc4.exe -o ui/images_rc.py ui/images/images.qrc Note, when … Read more

Best way to display logs in pyqt?

Adapted from Todd Vanyo’s example for PyQt5: import sys from PyQt5 import QtWidgets import logging # Uncomment below for terminal log messages # logging.basicConfig(level=logging.DEBUG, format=” %(asctime)s – %(name)s – %(levelname)s – %(message)s”) class QTextEditLogger(logging.Handler): def __init__(self, parent): super().__init__() self.widget = QtWidgets.QPlainTextEdit(parent) self.widget.setReadOnly(True) def emit(self, record): msg = self.format(record) self.widget.appendPlainText(msg) class MyDialog(QtWidgets.QDialog, QtWidgets.QPlainTextEdit): def __init__(self, parent=None): … Read more

Clear QLineEdit on click event

The solution is to promote QtDesigner use our custom QLineEdit where we implement the signal clicked with the help of mousePressEvent, this class will be called ClickableLineEdit and the file will be called ClickableLineEdit.py. ClickableLineEdit.py from PyQt5.QtCore import pyqtSignal from PyQt5.QtWidgets import QLineEdit class ClickableLineEdit(QLineEdit): clicked = pyqtSignal() def mousePressEvent(self, event): self.clicked.emit() QLineEdit.mousePressEvent(self, event) To … Read more

PyInstaller + UI Files – FileNotFoundError: [Errno 2] No such file or directory:

After scratching my head all weekend and looking further on SO, I managed to compile the standalone .exe as expected using the UI files. Firstly, I defined the following function using this answer Bundling data files with PyInstaller (–onefile) # Define function to import external files when using PyInstaller. def resource_path(relative_path): “”” Get absolute path … Read more