PyQt5: How to install/run Qt Designer
I struggled with this as well. The pyqt5-tools approach is cumbersome so I created a standalone installer for Qt Designer. It’s only 40 MB. Maybe you will find it useful!
I struggled with this as well. The pyqt5-tools approach is cumbersome so I created a standalone installer for Qt Designer. It’s only 40 MB. Maybe you will find it useful!
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
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
In Designer, activate the centralWidget and assign a layout, e.g. horizontal or vertical layout. Then your QFormLayout will automatically resize. Always make sure, that all widgets have a layout! Otherwise, automatic resizing will break with that widget! See also Controls insist on being too large, and won’t resize, in QtDesigner
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
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
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
The most common way to solve this is by using widget promotion. This will allow you to replace a widget defined in Qt Designer with your own custom class. The steps for doing this are as follows: In Qt Designer, select the QGraphicsView you want to replace, then right-click it and select Promote to… . … Read more
Qt Designer does not show all the Qt widget, and often we want to add our own widget through Qt, for that there are at least 2 solutions, the first is to create a plugin and load it to Qt Designer, and the other is simpler. promote the widget, the latter is what I will … Read more
This is probably due to changes in the way exceptions are dealt with in PyQt-5.5. To quote from the PyQt5 Docs: In PyQt v5.5 an unhandled Python exception will result in a call to Qt’s qFatal() function. By default this will call abort() and the application will terminate. Note that an application installed exception hook … Read more