PySide2 QMainWindow loaded from ui file not triggering window events

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

How do I load children from .ui file in PySide?

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

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

Qt Layout on QMainWindow

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