QWidget: Must construct a QApplication before a QWidget
-
Hello everyone,
I have already successfully created a layout for C++ with Qt and qwt support and wanted the same layout for Python projects.
I have already found many threads about my problem here (e.g. https://forum.qt.io/topic/115273/qwidget-must-construct-a-qapplication-before-a-qwidget/17) and have tried everything for a few days, but unfortunately my problem persists. I am working with VS Code, PyQt6, qwt and Python 3.12.0.
I think this will turn out like the previous threads, however maybe I really missed something or did something fundamentally wrong, I'm still pretty new and don't have much idea. JonB's solution (integrate QApplication via qwt.qt.QtGui) didn't work for me in this case, because I couldn't find a member like qt or something similar at qwt, only "qthelper" and there is probably nothing useful or I can't find it.The problem occurs when I want to add the qwt plot. The program is created and starts. For test purposes, I bound the addition of the qwt plot to a button. As soon as I press the button, the program is terminated and the message "QWidget: Must construct a QApplication before a QWidget" appears.
If I comment out everything in connection with the plot and replace it with the addition of a QPushButton, this also works and the button is added at the desired position.
When I set breakpoints, I see that the QApplication is built as desired and the function is only called when the button is pressed and the error occurs when the plot is created with:plot = qwt.QwtPlot("function plot")
Here is my code:
main.pyimport sys import qwt import resources import funktionen as fts import mainwindow as mwi from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton from PyQt6.QtCore import * from PyQt6.QtWidgets import * from ui_form import * if __name__ == "__main__": app = QApplication(sys.argv) widget = mwi.MainWindow() widget.setWindowFlags(QtCore.Qt.WindowType.FramelessWindowHint) widget.show() sys.exit(app.exec())
import funktionen as fts from ui_form import * class MainWindow(QtWidgets.QMainWindow): def __init__(self): QtWidgets.QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.but_beenden.clicked.connect(fts.on_but_beenden_clicked) self.ui.but_minimieren.clicked.connect(lambda checked: fts.on_but_minimieren_clicked(self)) self.ui.but_fenster.clicked.connect(lambda checked: fts.on_but_fenster_clicked(self)) self.ui.but_hauptmenu.clicked.connect(lambda checked: fts.on_but_hauptmenu_clicked(self)) self.ui.but_erster_menuunterpunkt.clicked.connect(lambda checked: fts.on_but_erster_menuunterpunkt_clicked(self)) self.ui.but_reload.clicked.connect(lambda checked: fts.on_but_reload_clicked(self)) def mousePressEvent(self, event): #Funktion um bei Maustastendruck die Zeigerposition auszulesen (benötigt zum Bewegen des Fensters) self.oldPos = event.globalPosition().toPoint() def mouseMoveEvent(self, event): #Funktion um bei Maustastendruck Fenster zu bewegen delta = QPoint (event.globalPosition().toPoint() - self.oldPos) self.move(self.x() + delta.x(), self.y() + delta.y()) self.oldPos = event.globalPosition().toPoint()
import qwt import sys from PyQt6.QtWidgets import QApplication def on_but_beenden_clicked(self): QApplication.quit() def on_but_minimieren_clicked(self): self.setWindowState(QtCore.Qt.WindowState.WindowMinimized) def on_but_hauptmenu_clicked(self): self.ui.stackedWidget.setCurrentIndex(0) def on_but_erster_menuunterpunkt_clicked(self): self.ui.stackedWidget.setCurrentIndex(1) def on_but_fenster_clicked(self): if self.isFullScreen(): self.showNormal() else: self.showFullScreen() def on_but_reload_clicked(self): plot = qwt.QwtPlot("Funktionsplot") plot.insertLegend(qwt.QwtLegend(), qwt.QwtPlot.BottomLegend) qwt.QwtPlotCurve.make(x, np.cos(x), "Cosinus", plot, linecolor="red", antialiased=True) qwt.QwtPlotCurve.make(x, np.sin(x), "Sinus", plot, linecolor="blue", antialiased=True) plot.resize(600, 300) self.ui.verticalLayout_4.addWidget(plot)
ui_form.py
# Form implementation generated from reading ui file 'mainwindow.ui' # # Created by: PyQt6 UI code generator 6.6.0 # # WARNING: Any manual changes made to this file will be lost when pyuic6 is # run again. Do not edit this file unless you know what you are doing. from PyQt6 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(1094, 858) MainWindow.setStyleSheet("background-color: rgb(33,37,40)") self.centralwidget = QtWidgets.QWidget(parent=MainWindow) self.centralwidget.setStyleSheet("@font-face {\n" " font-family: NovaFlat;\n" " src: url(:/fonts/Nova_Flat/NovaFlat-Regular.ttf) format(\"truetype\");\n" "}\n" "*{\n" "color: #fff;\n" "font-family: NovaFlat;\n" "font-size: 12px;\n" "border: nine;\n" "}\n" "#centralwidget{\n" "background-color: rgb(33, 43, 51);\n" "}\n" "#left_menu_widget\n" "{\n" "background-color: rgba(61, 80, 95, 100)\n" "}\n" "#header_frame, #frame_3{\n" "background-color: rgb(61, 80, 95);\n" "}\n" "#frame_4 QPushButton, #frame_5 QPushButton, #frame_6 QPushButton, #frame_7 QPushButton{\n" "padding: 10px;\n" "border-radius: 5px;\n" "background-color: rgba(33, 43, 51, 100);\n" "}\n" "#frame_11 QPushButton{\n" "background-color: rgb(61, 80, 95);\n" "border-radius: 15px;\n" "border: 3px solid rgb(120, 157, 186);\n" "}\n" "#frame_11 QPushButton:hover{\n" "background-color: rgb(120, 157, 186);\n" "}\n" "#QComboBox{text-align: right;}") self.centralwidget.setObjectName("centralwidget") self.horizontalLayout_11 = QtWidgets.QHBoxLayout(self.centralwidget) self.horizontalLayout_11.setObjectName("horizontalLayout_11") self.menu = QtWidgets.QWidget(parent=self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.menu.sizePolicy().hasHeightForWidth()) self.menu.setSizePolicy(sizePolicy) self.menu.setMinimumSize(QtCore.QSize(0, 840)) self.menu.setObjectName("menu") self.verticalLayout_68 = QtWidgets.QVBoxLayout(self.menu) self.verticalLayout_68.setObjectName("verticalLayout_68") self.premaframe = QtWidgets.QFrame(parent=self.menu) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.premaframe.sizePolicy().hasHeightForWidth()) self.premaframe.setSizePolicy(sizePolicy) self.premaframe.setMinimumSize(QtCore.QSize(183, 126)) self.premaframe.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.premaframe.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.premaframe.setObjectName("premaframe") self.horizontalLayout_23 = QtWidgets.QHBoxLayout(self.premaframe) self.horizontalLayout_23.setContentsMargins(0, 0, 0, 0) self.horizontalLayout_23.setObjectName("horizontalLayout_23") self.label_premabild = QtWidgets.QLabel(parent=self.premaframe) self.label_premabild.setMaximumSize(QtCore.QSize(183, 40)) self.label_premabild.setText("") self.label_premabild.setPixmap(QtGui.QPixmap(":/images/res/PREMA.jpg")) self.label_premabild.setScaledContents(True) self.label_premabild.setObjectName("label_premabild") self.horizontalLayout_23.addWidget(self.label_premabild) self.verticalLayout_68.addWidget(self.premaframe, 0, QtCore.Qt.AlignmentFlag.AlignTop) self.erster_menupunktframe = QtWidgets.QFrame(parent=self.menu) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.erster_menupunktframe.sizePolicy().hasHeightForWidth()) self.erster_menupunktframe.setSizePolicy(sizePolicy) self.erster_menupunktframe.setMinimumSize(QtCore.QSize(0, 0)) self.erster_menupunktframe.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.erster_menupunktframe.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.erster_menupunktframe.setObjectName("erster_menupunktframe") self.verticalLayout_69 = QtWidgets.QVBoxLayout(self.erster_menupunktframe) self.verticalLayout_69.setObjectName("verticalLayout_69") self.erster_menupunkt = QtWidgets.QLabel(parent=self.erster_menupunktframe) self.erster_menupunkt.setStyleSheet("font: 14pt \"Times New Roman\";") self.erster_menupunkt.setObjectName("erster_menupunkt") self.verticalLayout_69.addWidget(self.erster_menupunkt, 0, QtCore.Qt.AlignmentFlag.AlignHCenter) spacerItem = QtWidgets.QSpacerItem(20, 10, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) self.verticalLayout_69.addItem(spacerItem) self.but_erster_menuunterpunkt = QtWidgets.QPushButton(parent=self.erster_menupunktframe) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/icons/res/1000001768.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.but_erster_menuunterpunkt.setIcon(icon) self.but_erster_menuunterpunkt.setIconSize(QtCore.QSize(22, 22)) self.but_erster_menuunterpunkt.setObjectName("but_erster_menuunterpunkt") self.verticalLayout_69.addWidget(self.but_erster_menuunterpunkt) self.verticalLayout_68.addWidget(self.erster_menupunktframe, 0, QtCore.Qt.AlignmentFlag.AlignHCenter|QtCore.Qt.AlignmentFlag.AlignTop) self.zweiter_menpunktframe = QtWidgets.QFrame(parent=self.menu) self.zweiter_menpunktframe.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.zweiter_menpunktframe.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.zweiter_menpunktframe.setObjectName("zweiter_menpunktframe") self.verticalLayout_68.addWidget(self.zweiter_menpunktframe) self.dritter_menupunktframe = QtWidgets.QFrame(parent=self.menu) self.dritter_menupunktframe.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.dritter_menupunktframe.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.dritter_menupunktframe.setObjectName("dritter_menupunktframe") self.verticalLayout_68.addWidget(self.dritter_menupunktframe) self.horizontalLayout_11.addWidget(self.menu) self.anzeigeframe = QtWidgets.QFrame(parent=self.centralwidget) self.anzeigeframe.setMinimumSize(QtCore.QSize(0, 840)) self.anzeigeframe.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.anzeigeframe.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.anzeigeframe.setObjectName("anzeigeframe") self.verticalLayout_66 = QtWidgets.QVBoxLayout(self.anzeigeframe) self.verticalLayout_66.setObjectName("verticalLayout_66") self.kopfframe = QtWidgets.QFrame(parent=self.anzeigeframe) self.kopfframe.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.kopfframe.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.kopfframe.setObjectName("kopfframe") self.horizontalLayout_19 = QtWidgets.QHBoxLayout(self.kopfframe) self.horizontalLayout_19.setObjectName("horizontalLayout_19") self.kopfframe_links = QtWidgets.QFrame(parent=self.kopfframe) self.kopfframe_links.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.kopfframe_links.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.kopfframe_links.setObjectName("kopfframe_links") self.horizontalLayout_20 = QtWidgets.QHBoxLayout(self.kopfframe_links) self.horizontalLayout_20.setObjectName("horizontalLayout_20") self.but_hauptmenu = QtWidgets.QPushButton(parent=self.kopfframe_links) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.but_hauptmenu.sizePolicy().hasHeightForWidth()) self.but_hauptmenu.setSizePolicy(sizePolicy) self.but_hauptmenu.setMaximumSize(QtCore.QSize(32, 32)) self.but_hauptmenu.setText("") icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/icons/res/home.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.but_hauptmenu.setIcon(icon1) self.but_hauptmenu.setIconSize(QtCore.QSize(32, 32)) self.but_hauptmenu.setObjectName("but_hauptmenu") self.horizontalLayout_20.addWidget(self.but_hauptmenu) self.but_reload = QtWidgets.QPushButton(parent=self.kopfframe_links) self.but_reload.setMaximumSize(QtCore.QSize(32, 32)) self.but_reload.setText("") icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/icons/res/loop.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.but_reload.setIcon(icon2) self.but_reload.setIconSize(QtCore.QSize(32, 32)) self.but_reload.setObjectName("but_reload") self.horizontalLayout_20.addWidget(self.but_reload) self.horizontalLayout_19.addWidget(self.kopfframe_links, 0, QtCore.Qt.AlignmentFlag.AlignLeft) self.kopfframe_mitte = QtWidgets.QFrame(parent=self.kopfframe) self.kopfframe_mitte.setStyleSheet("font: 700 14pt \"Times New Roman\";\n" "") self.kopfframe_mitte.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.kopfframe_mitte.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.kopfframe_mitte.setObjectName("kopfframe_mitte") self.verticalLayout_67 = QtWidgets.QVBoxLayout(self.kopfframe_mitte) self.verticalLayout_67.setObjectName("verticalLayout_67") self.label_programmname = QtWidgets.QLabel(parent=self.kopfframe_mitte) self.label_programmname.setObjectName("label_programmname") self.verticalLayout_67.addWidget(self.label_programmname, 0, QtCore.Qt.AlignmentFlag.AlignHCenter) self.horizontalLayout_19.addWidget(self.kopfframe_mitte) self.kopfframe_rechts = QtWidgets.QFrame(parent=self.kopfframe) self.kopfframe_rechts.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.kopfframe_rechts.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.kopfframe_rechts.setObjectName("kopfframe_rechts") self.horizontalLayout_21 = QtWidgets.QHBoxLayout(self.kopfframe_rechts) self.horizontalLayout_21.setObjectName("horizontalLayout_21") self.but_minimieren = QtWidgets.QPushButton(parent=self.kopfframe_rechts) self.but_minimieren.setMaximumSize(QtCore.QSize(32, 32)) self.but_minimieren.setText("") icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/icons/res/minus-sign.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.but_minimieren.setIcon(icon3) self.but_minimieren.setIconSize(QtCore.QSize(32, 32)) self.but_minimieren.setObjectName("but_minimieren") self.horizontalLayout_21.addWidget(self.but_minimieren) self.but_fenster = QtWidgets.QPushButton(parent=self.kopfframe_rechts) self.but_fenster.setMaximumSize(QtCore.QSize(32, 32)) self.but_fenster.setText("") icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(":/icons/res/expand.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.but_fenster.setIcon(icon4) self.but_fenster.setIconSize(QtCore.QSize(32, 32)) self.but_fenster.setObjectName("but_fenster") self.horizontalLayout_21.addWidget(self.but_fenster) self.but_beenden = QtWidgets.QPushButton(parent=self.kopfframe_rechts) self.but_beenden.setMaximumSize(QtCore.QSize(32, 32)) self.but_beenden.setText("") icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap(":/icons/res/cross.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.but_beenden.setIcon(icon5) self.but_beenden.setIconSize(QtCore.QSize(32, 32)) self.but_beenden.setObjectName("but_beenden") self.horizontalLayout_21.addWidget(self.but_beenden) self.horizontalLayout_19.addWidget(self.kopfframe_rechts, 0, QtCore.Qt.AlignmentFlag.AlignRight) self.verticalLayout_66.addWidget(self.kopfframe) self.stackedWidget = QtWidgets.QStackedWidget(parent=self.anzeigeframe) self.stackedWidget.setObjectName("stackedWidget") self.startseite = QtWidgets.QWidget() self.startseite.setObjectName("startseite") self.verticalLayout = QtWidgets.QVBoxLayout(self.startseite) self.verticalLayout.setObjectName("verticalLayout") self.label_startseite = QtWidgets.QLabel(parent=self.startseite) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Maximum, QtWidgets.QSizePolicy.Policy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.label_startseite.sizePolicy().hasHeightForWidth()) self.label_startseite.setSizePolicy(sizePolicy) self.label_startseite.setObjectName("label_startseite") self.verticalLayout.addWidget(self.label_startseite, 0, QtCore.Qt.AlignmentFlag.AlignHCenter) self.frame_startseite = QtWidgets.QFrame(parent=self.startseite) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.frame_startseite.sizePolicy().hasHeightForWidth()) self.frame_startseite.setSizePolicy(sizePolicy) self.frame_startseite.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.frame_startseite.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.frame_startseite.setObjectName("frame_startseite") self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.frame_startseite) self.verticalLayout_3.setObjectName("verticalLayout_3") self.verticalLayout.addWidget(self.frame_startseite) self.stackedWidget.addWidget(self.startseite) self.erste_Seite = QtWidgets.QWidget() self.erste_Seite.setObjectName("erste_Seite") self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.erste_Seite) self.verticalLayout_2.setObjectName("verticalLayout_2") self.label_ueberschrift_erster_menuunterpunkt = QtWidgets.QLabel(parent=self.erste_Seite) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Maximum, QtWidgets.QSizePolicy.Policy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.label_ueberschrift_erster_menuunterpunkt.sizePolicy().hasHeightForWidth()) self.label_ueberschrift_erster_menuunterpunkt.setSizePolicy(sizePolicy) self.label_ueberschrift_erster_menuunterpunkt.setObjectName("label_ueberschrift_erster_menuunterpunkt") self.verticalLayout_2.addWidget(self.label_ueberschrift_erster_menuunterpunkt, 0, QtCore.Qt.AlignmentFlag.AlignHCenter) self.erste_Seite_erster_frame = QtWidgets.QFrame(parent=self.erste_Seite) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.erste_Seite_erster_frame.sizePolicy().hasHeightForWidth()) self.erste_Seite_erster_frame.setSizePolicy(sizePolicy) self.erste_Seite_erster_frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.erste_Seite_erster_frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.erste_Seite_erster_frame.setObjectName("erste_Seite_erster_frame") self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.erste_Seite_erster_frame) self.verticalLayout_4.setObjectName("verticalLayout_4") self.verticalLayout_2.addWidget(self.erste_Seite_erster_frame) self.erste_Seite_zweiter_frame = QtWidgets.QFrame(parent=self.erste_Seite) self.erste_Seite_zweiter_frame.setMinimumSize(QtCore.QSize(0, 337)) self.erste_Seite_zweiter_frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.erste_Seite_zweiter_frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.erste_Seite_zweiter_frame.setObjectName("erste_Seite_zweiter_frame") self.verticalLayout_2.addWidget(self.erste_Seite_zweiter_frame) self.stackedWidget.addWidget(self.erste_Seite) self.verticalLayout_66.addWidget(self.stackedWidget) self.horizontalLayout_11.addWidget(self.anzeigeframe) MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) self.stackedWidget.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.erster_menupunkt.setText(_translate("MainWindow", "1. Menupunkt")) self.but_erster_menuunterpunkt.setText(_translate("MainWindow", "1. Menuunterpunkt")) self.label_programmname.setText(_translate("MainWindow", "Überschrift")) self.label_startseite.setText(_translate("MainWindow", "Startseite")) self.label_ueberschrift_erster_menuunterpunkt.setText(_translate("MainWindow", "1. Menuunterpunkt"))
I can also upload the resources somewhere if required.
Don't go to too much trouble on my account, but I am happy to receive any answer.
I still have about 5 hours to test, unfortunately I won't be able to test answers after that until Monday.Thanks in advance,
Marco -
Hi,
What is
funktionen.py
for ? It seems you have put there stuff that should be part of MainWindow. -
@SGaist As with my C++ project, I wanted to separate my functions from the class definition. This is probably not done in Python, but I only did it as part of the troubleshooting and apparently it doesn't cause any problems (yet?!). I will probably put it back into MainWindow in the final version in order to stay closer to Python programming, but in my particular case it makes sense for testing purposes for the sake of clarity. I still have many more functions from C++ to implement.
-
The thing is, it's not pythonic at all and makes your code harder to follow beside creating several lambdas with no benefits.
I would recommend putting these methods back to the class where they belong. It will remove one possible source of issues to debug your start problem.