ImportError: No module named ‘resource_rc’
You should have a file called resource.qrc, this must be converted to .py, this or you can do it by executing: pyrcc5 resource.qrc -o resource_rc.py
You should have a file called resource.qrc, this must be converted to .py, this or you can do it by executing: pyrcc5 resource.qrc -o resource_rc.py
It seems that you have a confusion, but for you to understand call the test method of TestWindow: import os from PySide2 import QtCore, QtWidgets, QtUiTools class TestWindow(QtWidgets.QMainWindow): def __init__(self, parent=None): super(TestWindow, self).__init__(parent) loader = QtUiTools.QUiLoader() file = QtCore.QFile(os.path.abspath(“ui/mainwindow.ui”)) file.open(QtCore.QFile.ReadOnly) self.window = loader.load(file, parent) file.close() self.window.show() self.show() def resizeEvent(self, event): print(“resize”) if __name__ == ‘__main__’: … Read more
Option 1: Promoted I suppose you mean inserting a QChartView, because QChartView inherits from QGraphicsView, this would be a good option, for this we do the following: first add QT += charts in the .pro place the QGraphicsView to the design. Right click on the QGraphicsView and select Promote to… When doing the above, a … Read more
UPDATE: The original solution below was written for PySide (Qt4). It still works with both PySide2 (Qt5) and PySide6 (Qt6), but with a couple of provisos: The connectSlotsByName feature requires that the corresponding slots are decorated with an appropriate QtCore.Slot. Custom/Promoted widgets aren’t handled automatically. The required classes must be explicily imported and registered with … Read more
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
Don’t replace the widgets at runtime: promote the widgets in Qt Designer so that the line-edits are automatically replaced by your custom class when the GUI module is generated. Here’s how to promote a widget to use a custom class: In Qt Designer, select all the line-edits you want to replace, then right-click them and … 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
If you want to do it with code instead of using QtCreator, you could set the layout in a QWidget and then set the QWidget as the central widget of the main window like this: #include <QtGui> #include <QWidget> #include <QHBoxLayout> #include “mainwindow.h” MainWindow::MainWindow() { // Set layout QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(myWidget1); layout->addWidget(myWidget2); … Read more
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!
Layouts are actually easy to understand “I think”. 🙂 A simple explanation of layouts can be found in the QT book “C++ Gui programming with QT 2nd edition“ What you should be aware of regarding layouts and their size policies Most Qt widgets have a size policy. This size policy tells the system how the … Read more